Details of the remote connection mysql authorization method

  • 2020-05-13 03:41:39
  • OfStack

Now we have the mysql database on the server, remote access, we don't want to publish the root account, so we created the demo account, which allows the demo account to access the shandong library in the mysql database from anywhere.
Plan 1:
Run on the machine where mysql is installed:
1: create user users
 
CREATE USER demo IDENTIFIED BY  " 123456 "  

2,
 
mysql>GRANT ALL PRIVILEGES ON shandong.* TO 'demo'@'%'WITH GRANT OPTION 
// Give any host access to the data, or do the following  
GRANT ALL PRIVILEGES ON shandong.* TO 'demo'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION; 

3,
 
mysql>FLUSH PRIVILEGES 
// Changes to take effect  

4,
 
mysql>EXIT 
// exit MySQL Server so that you can use it on any other host demo login  

reference
In addition, when using the client to connect mysql, it is found that the connection cannot be made, so it seems that the user needs to be reauthorized. The operation is as follows:
[root@cicro108 mysql]# bin/mysql -uroot -p -h 127.0.0.1 -A cws3
Enter password:
Welcome to the MySQL monitor. Commands end with or /g.
Your MySQL connection id is 1863 to server version: 4.1.20-standard
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql > grant ALL PRIVILEGES ON *.* to root@"%" identified by "mysql";
Query OK, 0 rows affected (0.17 sec)
After this change in permissions is discovered, the remote will still not be able to connect, but it will work with the following actions.
mysql > grant ALL PRIVILEGES ON *.* to root@"%" identified by "mysql" WITH GRANT OPTION;
Query OK, 0 rows affected (0.17 sec)
At this point, root can be connected remotely, although other non-root users can also be connected remotely.

Scheme 2:
MySQL 1130 error resolution:
This error occurred while connecting MySQL via MySQL-Front or MySQL administrator
ERROR 1130: Host ***.***.***.*** is not allowed to connect to this MySQL server
Note that the connected user account does not have remote connection permissions and can only log in from the local machine (localhost).
You need to change the host entry in the user table in the MySQL database
Call localhost %

How to do it: log in to MySQL
First, use MySQL;
An error occurred while update was being provided by someone else.
MySQL > update user set host='%' where user = 'root';
ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'
Then I checked the host information of the database as follows:
MySQL > select host from user where user = 'root';
+-----------------------+
| host |
+-----------------------+
| % |
| 127.0.0.1 |
| localhost.localdomain |
+-----------------------+
3 rows in set (0.00 sec)
host already has a value of %, so run the command directly:
 
MySQL>flush privileges; 

Connect with MySQL administrator... Success!!!!!

Related articles: