报错
四步解决:
1.登入到MySQL数据库中
2.执行 use mysql;
进入到mysql库
3.进入后执行 update user set host = '%' where user = 'root';
语句,报错也不用理会
4.执行FLUSH PRIVILEGES;
刷新MySQL的权限相关表
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)
如果还是连接不上就删除连接,然后重新新建连接。
提供简单脚本
[root@mysqld01 ~]# cat navicat.sh
#!/bin/bash
read -p "Please enter your MySQL password:" pass
mysql -uroot -p$pass << EOF
use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
EOF
echo "ok!"