MySQL implements password-less login (mysql_config_editor)
There is a business requirement to dump MySQL database data from a host, but you do not want the business staff to know the password of a specific MySQL user. You can use the mysql_config_editor command to achieve this.
First, the test environment
A machine IP is 192.168.3.171
The IP of machine B is 192.168.3.173
Intend to connect from B to A without a "password"
Database versions of An and B
(root@localhost) [(none)] > select version ()
+-+
| | version () |
+-+
| | 5.7.17-log |
+-+
1 row in set (0.00 sec) 2, create a test user on machine An and grant permissions
(root@localhost) [(none)] > create user gl@'192.168.3.173' identified by 'onlygl'
Query OK, 0 rows affected (0.00 sec)
(root@localhost) [(none)] > grant all on *. * to gl@'192.168.3.173'
Query OK, 0 rows affected (0. 01 sec) 3, execute the following command on machine B and enter the password of the gl user
Mysql_config_editor set-- login-path=gl-- host=192.168.3.171-- user=gl-- password 4. After executing the above command, you can find a hidden file .mylogin.cnf in the directory of home, as follows:
-rw- 1 root root 136 Feb 27 19:04. Mylogin.cnf five, check the contents of the file.
[root@mysqltest] # mysql_config_editor print-- all
[gl]
User = gl
Password = *
Host = 192.168.3.1716, log in
[root@mysqltest] # mysql-- login-path=gl
Welcome to the MySQL monitor. Commands end with; or\ g.
Your MySQL connection id is 311
Server version: 5.7.17-log Mysqlma
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respective
Owners.
Type 'help;'or'\ h'for help. Type'\ c'to clear the current input statement. (gl@192.168.3.171) [(none)] > 7. If you don't want to use it, delete it with the following command
Mysql_config_editor remove-login-path= GL8, scope of application
Mysql
Mysqladmin
Mysqldump9, summary
1. It is obvious that after the user's password has been changed, the login-path needs to be recreated
two。 This feature is only supported in version 5.6.6 or above.