登陆到数据
mysql -uroot -p密码
use mysql;
select host,user,password from user;
可以看到 user 为 root,host 为 localhost 的话,说明 MySQL 只允许本机连接,那么外网,本地软件客户端就无法连接了。
解决方案:
执行如下命令:
update user set host='%' where user ='root';
flush privileges;
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host='%' where user ='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
查看是否修改正常:
mysql> select host,user from user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
3 rows in set (0.00 sec)
mysql>