解决Navicat Premium连接MySQL 报错 “can‘t connect to MySQL server on unkown error”

报错
在这里插入图片描述四步解决:
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!"

猜你喜欢

转载自blog.csdn.net/weixin_45310323/article/details/109990685