天天看点

Host is not allowed to connect to this MySQL server错误的解决办法

错误描述

我先做了这些工作:服务器用的 Windows Server 2012。配置好服务器上的MySQL。防火墙允许mysqld.exe 。

然后在我自己的电脑上用 workbench 连接服务器上的 MySQL 发现无法连接。提示错误: Host ‘xxx.xxx.xxx.xxx’ is not allowed to connect to this MySQL server 。其中 ‘xxx.xxx.xxx.xxx’ 是我自己的电脑的IP。

解决方法

远程桌面连接到服务器。调用

mysql -u root -p

命令打开客户端,连接数据库。执行如下命令并得到返回结果:

mysql> use mysql
mysql> select t.host from user t where t.user='root';
+--------------+
|  host        |
+--------------+
|  localhost   |
+--------------+
           

这个返回结果说明现在 root 用户只允许在服务器的本地登录。

执行如下命令:

然后重启 MySQL 服务就可以了。

原文地址