Solution to the problem that Navicat cannot connect to the MySQL8.0 version database in LINUX

1. Program error

2. Project background

        The MySQL8.0 version database is installed in the Linux system, and the Linux firewall is also set to open port 3306, but an error is still reported when connecting in Navicat. The error is: ERROR 1130: Host '192.168.232.128' is not allowed to connect to this MySQL server database does not allow connection.

3. Error analysis

        At this time, because I have set up the firewall to open port 3306, but still cannot connect, I considered whether the user I am connecting to the database has insufficient permissions, because when creating a new MySQL connection, there will be a default mysql database. There is a user table in the database , which is used to set the permissions of all users.

         So I queried the user field and host field in the user table, and found that the host field of the root user I wanted to connect to the database only had the localhost loopback address, that is, only the root user was allowed to connect to the database from the localhost or 127.0.0.1 address . At this time, we need to change the host field of the root user to '%', because if the wildcard character % is used as the host, the specified user is allowed to connect from any host .

4. Error resolution

(1) Turn off the Linux firewall first

systemctl stop firewalld.service close firewall command

systemctl start firewalld.service open firewall command

        But in fact, we do not recommend turning off the Linux firewall directly , because it is very unsafe and prone to external malicious attacks.

(2) Do not close the Linux firewall, but open port 3306 in it

        firewall-cmd --zone=public --add-port=3306/tcp --permanent

         When the word "success" appears, it means that it has been successfully opened. I have a warning here because it has already been opened.

(3) Restart the firewall (very important, it must be refreshed to take effect)

        firewall-cmd --reload

(4) Log in to the database (the premise of everything is that the database service is open)

        mysql -u root -p

(5) View the host field of all users

        select user,host from user;

         At this time, you can see that the host field of the root user is localhost, which means that only the local address is allowed to connect to the database.

(6) Modify the host field of the root user

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

        If you use the wildcard % as the host, the specified user is allowed to connect from any host .

(7) Refresh privileges after modification

        flush privileges;       

 (8) Test the connection again

Guess you like

Origin blog.csdn.net/weixin_64709241/article/details/129506994
Recommended