天天看点

IDEA 连接阿里云-轻量应用服务器上的 MySQL 提示 Host x.x.x.x is not allowed to connect to this MySQL server

使用 IDEA 连接阿里云-轻量应用服务器上的 MySQL,出现 Error 信息,如下图红框所示。

IDEA 连接阿里云-轻量应用服务器上的 MySQL 提示 Host x.x.x.x is not allowed to connect to this MySQL server

点击 Error 信息右边的 view ,会出现 Error 的详细信息,如下图所示。

IDEA 连接阿里云-轻量应用服务器上的 MySQL 提示 Host x.x.x.x is not allowed to connect to this MySQL server

解决:

我是 Windows 系统的服务器,通过远程桌面连接了服务器,并且进入了服务器中的 MySQL ,输入 ​

​show databases;​

IDEA 连接阿里云-轻量应用服务器上的 MySQL 提示 Host x.x.x.x is not allowed to connect to this MySQL server

输入 ​

​use mysql;​

​​ 、​

​update user set host='%' where user='root';​

IDEA 连接阿里云-轻量应用服务器上的 MySQL 提示 Host x.x.x.x is not allowed to connect to this MySQL server

为什么要这样设置呢?这是因为数据库默认设置只允许本地程序进行连接,也就是只允许本地主机连接数据库,如默认设置 ​

​host='localhost'​

​​,如果需要设置其他主机也可以连接数据库,我们需要设置 ​

​host='%'​

​。

记得要重启一下数据库。

如果有说错的地方,请指正,万分感谢。

这样就可以正常连接数据库了。

IDEA 连接阿里云-轻量应用服务器上的 MySQL 提示 Host x.x.x.x is not allowed to connect to this MySQL server