客户端连接报错

这个问题是因为用户在数据库服务器中的mysql数据库中的user的表中没有权限。

centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server_本地连接

解决步骤

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

centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server_远程连接_02

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

centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server_远程连接_03

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

centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server_本地连接_04

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

centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server_本地连接_05

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

centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server_远程连接_06

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

6、修改user表中的Host

%表示开启远程连接,且没有限制,在任何主机都可以登录;(%不包含localhost

update user set Host='%' where User='root' and Host="localhost";,但是会出现下面的问题,最好是新增一行Host为%的数据

centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server_mysql数据库_07

centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server_本地连接_08

上面这样改了后,会导致xshell连接看不到所有的数据库(xshell表示本地连接,因为xshell先连接到服务器,然后在服务器登录数据库),localhost才表示本地连接(注意:上面localhost没有设置密码,所以本地连接,就不用密码;navicat表示远程连接,需要密码)

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

 centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server_远程连接_09

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

centos7中,mysql连接报错:1130 - Host ‘118.111.111.111’ is not allowed to connect to this MariaDB server_本地连接_10



声明:如有侵权,请联系删除。

============================= 升职加薪 ==========================