错误现象
修改完info.php文件以后测试
<?php
$link=mysqli_connect('127.0.0.1','zabbix','admin123');
if ($link) echo "连接成功!!!";
else echo "连接失败!!!";
?>
错误原因
有空用户名称占用导致本地无法登陆
[root@pyy ~] # mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user | host |
+--------+-----------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | pyy |
| root | pyy |
+--------+-----------+
7 rows in set (0.00 sec)
解决办法
删掉空用户
MariaDB [(none)]> drop user ''@localhost;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> drop user ''@pyy;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> select user,host from mysql.user;
+--------+-----------+
| user | host |
+--------+-----------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| root | pyy |
+--------+-----------+
5 rows in set (0.00 sec)
此时所有用户都一一对应,再去测试一下