MySQL 5.6 configure a secure encrypted password
In shell scripts, you usually configure the plaintext password for the database, which is not secure. After MySQL version 5.6, you can configure a secure encrypted password file, which can then be used to connect to the database without entering a plaintext password.
Configure a secure encrypted password for local root users
[root@localhost] # mysql_config_editor set-- user=root-- password
Enter password:
Try to connect to the database
[root@localhost ~] # mysql
Welcome to the MySQL monitor. Commands end with; or\ g.
Your MySQL connection id is 179
Server version: 5.6.31-77.0-log Percona Server (GPL), Release 77.0, Revision 5c1061c
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.
Mysql > select user ()
+-+
| | user () |
+-+
| | root@localhost |
+-+
1 row in set (0.00 sec)
Mysql > exit
Bye
Go to the home directory, look at the encrypted password file, and you can see the garbled code inside.
[root@localhost ~] # cd
[root@localhost ~] # cat .mylogin.cnf
?
? # [root@localhost ~] # paired EQs SB??hH?XJ?-&?P?-/? a\ Swarm T SB??hH?XJ?-&?P?-/? | M5?
Configure the specified remote database connection user
[root@localhost] # mysql_config_editor set-login-path=remote-host=192.168.56.101-user=ss7-password
Enter password:
View a list of configured encrypted passwords
[root@localhost] # mysql_config_editor print-- all
[client]
User = root
Password = *
[remote]
User = ss7
Password = *
Host = 192.168.56.101
Try to connect to the database
[root@localhost] # mysql-- login-path=remote
Welcome to the MySQL monitor. Commands end with; or\ g.
Your MySQL connection id is 181
Server version: 5.6.31-77.0-log Percona Server (GPL), Release 77.0, Revision 5c1061c
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.
Mysql > select user ()
+-+
| | user () |
+-+
| | ss7@192.168.56.101 |
+-+
1 row in set (0.00 sec)
Mysql > exit
Bye
Connect root local users with the-- login-path option
[root@localhost] # mysql-- login-path=client
Welcome to the MySQL monitor. Commands end with; or\ g.
Your MySQL connection id is 182
Server version: 5.6.31-77.0-log Percona Server (GPL), Release 77.0, Revision 5c1061c
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
Affiliates. Other names may be trademarks of their respective
Owners.
Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.
Mysql > select user ()
+-+
| | user () |
+-+
| | root@localhost |
+-+
1 row in set (0.00 sec)