mysql_config_editor出现在mysql5.6.6以后的版本,可以给指定的连接和密码生成一个加密文件.mylogin.cnf,默认位于当前用户家目录下。通过该文件可以使用mysql、mysqladmin等直接登录,避免明文密码出现在脚本中。
notice:使用该特性要求当前主机的mysql版本在5.6.6版本及以上,对将要登陆的mysql服务器版本没有要求。
Usage:
生成加密文件:
[root@master ~]# mysql_config_editor set --login-path=jjscj --host=192.168.1.190 --user=jjscj --password
Enter password:
Enter password:
[root@master ~]# ll ~/.mylogin.cnf
-rw------- 1 root root 248 Aug 28 14:58 /root/.mylogin.cnf
-rw------- 1 root root 248 Aug 28 14:58 /root/.mylogin.cnf
使用加密文件登录:
[root@master ~]# mysql --login-path=jjscj
Welcome to the MySQL monitor.
Welcome to the MySQL monitor.
查看当前主机上的加密文件:
[root@master ~]# mysql_config_editor print --all
[local]
user = root
password = *****
host = localhost
[jjscj]
user = jjscj
password = *****
host = 192.168.1.190
[local]
user = root
password = *****
host = localhost
[jjscj]
user = jjscj
password = *****
host = 192.168.1.190
[remote]
user = jjscj
password = *****
host = 192.168.1.190
删除某个加密登陆:
[root@master ~]# mysql_config_editor remove --login-path=remote
[root@master ~]# mysql_config_editor print --all
[local]
user = root
password = *****
host = localhost
[jjscj]
user = jjscj
password = *****
host = 192.168.1.190
[root@master ~]# mysql_config_editor print --all
[local]
user = root
password = *****
host = localhost
[jjscj]
user = jjscj
password = *****
host = 192.168.1.190
重置所有:
[root@master ~]# mysql_config_editor reset