Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

时间:2023-03-08 16:34:11
Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

这个问题是因为在数据库服务器中的mysql数据库中的user的表中没有权限(也可以说没有用户),下面将记录我遇到问题的过程及解决的方法。

  在搭建完LNMP环境后用Navicate连接出错

  遇到这个问题首先到mysql所在的服务器上用连接进行处理

  1、连接服务器: mysql -u root -p

Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

  2、看当前所有数据库:show databases;

Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

  3、进入mysql数据库:use mysql;

Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

  4、查看mysql数据库中所有的表:show tables;

Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

  5、查看user表中的数据:select Host, User,Password from user;

Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

上面localhost表示只允许本地连接,不能远程连接

Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

  6、修改user表中的Host:update user set Host='%' where User='root' and Host="localhost";

Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

  7、最后刷新一下:flush privileges;

Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server

  8、重新在Navicate中测试一下:

Mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server