The client connects to Mysql and reports an error

error message

Mysql is installed in the Centos system, and an error is reported when using Naticat to connect to Mysql. The information is as follows:

Host '192.168.237.1' is not allowed to connect to this MariaDB server 

solution

1. Enter Mysql

mysql -u root -p

enter password

[root@localhost src]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 360
Server version: 10.2.43-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

2. Enter the mysql database

use mysql;

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

3. View the user's host

select host, user,password from user;

MariaDB [mysql]> select host, user,password from user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *D06A34E97174580E449FBB7AAF0481C1744FCB |
| 127.0.0.1 | root | *D06A34E97174580E449FBB7AAF0481C1744FCB |
| ::1       | root | *D06A34E97174580E449FBB7AAF0481C1744FCB |
| %         | root | *2470C0C06DEE42F618BB99005ADCA2EC9D1E19 |
+-----------+------+-------------------------------------------+
4 rows in set (0.00 sec)

At this time, it is found that the password corresponding to the host is % is different from the other three, and % means that it is allowed to connect to the Mysql database from any host.

4. Delete the record where host is %

delete from user where host = '%';

MariaDB [mysql]> delete from user where host = '%';
Query OK, 1 row affected (0.00 sec)

5. Authorization allows connection from any host

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxx' WITH GRANT OPTION;

  • Note: xxx is the password of the root user. If you change other users, you can change root to other users.
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxx' WITH GRANT OPTION; 
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

6. Refresh the authorization to make it effective

FLUSH PRIVILEGES;

MariaDB [mysql]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

I feel that the above steps 5 and 6 can be combined into one step, and the host is changed to %, and the password is the other 3 passwords, but I haven’t tried it. I can try it next time.

update user set password = 'xxxx' where host = '%'; 

Guess you like

Origin blog.csdn.net/ling1998/article/details/130229809