How to handle the prompt when connecting to the MySQL server: 1130-Host XXX is not allowed to connect to this MySQL server

This is a problem that occurs when using tools such as Navicat to connect to the Mysql server. The reason is that the corresponding mysql server does not allow remote connections. I have encountered it many times, and it seems to be quite frequent. I made a record for future reference and for everyone’s reference.

The problem appears as follows:

What is recorded this time is the situation of the MySQL server on Windows. If it is Linux, it can be handled in a similar way.

1. Open the command prompt on the server (this method has already configured the environment variables. If the environment variables are not configured, it will prompt that it is not an internal or external command. You can also configure the environment variables or jump directly to the mysql installation directory) :

2. Log in to mysql using the command:

mysql -uroot -p (this command requires a separate password) or mysql -uroot -pXXX directly with the password

3. Go to the mysql library

use mysql;

 4. Query the clients that the current user can log in to: Query from the user table of the mysql library

select user,password,host from user;

You can see that the root user is only allowed to log in on localhost, so we need to change it so that it can log in from other hosts.

 5. Update the clients that root users can log in to:

update user set host=@'%' where user='root' and host='localhost' limit 1;

And use the command: flush privileges; to complete the update

6. Confirm the modification:

You can see that the password-protected root host no longer displays localhost. When you connect again, you find that the connection can be successful and no more errors are reported:

When logging in to the database server, the logged-in host, user name, and password will be verified. If any of them does not match the original information in the database, login failure will occur. Specific issues can be analyzed in detail.

=====================================================================

When I was dealing with this problem before, I also found a solution. I forgot the specific information link, but it is roughly like this:

In this method, there is an error, but the information at the time said that it can be ignored and it can be handled successfully. However, I remembered that this was not possible before, so I changed the method recorded above. If you are curious, you can try it.

Another thing to consider is to turn off the firewall of the mysql server or allow the corresponding port number, otherwise an error may still be reported.

In addition, it should be noted that this solution may cause another pitfall. For processing methods, please refer to:About mysql Error 1045 (28000): Access denied for user 'root'@ How to handle 'localhost'(using password:YES)_yeyuningzi's blog-CSDN blog

Guess you like

Origin blog.csdn.net/yeyuningzi/article/details/120509321