有时候客户端连接mysql需要指定密码时(如用zabbix监控mysql)5.6后数据库会给出个警告信息
mysql -uroot -pxxxx
Warning: Using a password on the command line interface can be insecure.
但是在zabbix里监控就不好取值了,除了在my.cnf中加入,但这样需要重启数据库而且也暴露了数据库密码
[mysqladmin]
user=zabbix
password=xxxxxx
[mysql]
user=zabbix
password=xxxxxx
使用mysql_config_editor可以实现将密码保存在一个配置中,下次登录不用输入用户名密码
login-path是MySQL5.6开始支持的新特性。通过借助mysql_config_editor工具将登陆MySQL服务的认证信息加密保存在.mylogin.cnf文件(默认位于用户主目录) 。之后,MySQL客户端工具可通过读取该加密文件连接MySQL,避免重复输入登录信息,避免敏感信息暴露
mysql_config_editor set --login-path=local --host=localhost --user=root --password
Enter password: (输入密码)
–login-path=name 在登录文件中为login path添加名字
–host=name 添加host到登陆文件中
–password 在登陆文件中添加密码(该密码会被mysql_config_editor自动加密)
–user 添加用户名到登陆文件中
–port=name 添加登陆端口到登陆文件中
–socket=name 添加sock文件路径到登陆文件中
显示配置:
mysql_config_editor print --login-path=test #显示执行的login-path配置
mysql_config_editor print --all #显示所有的login-path信息
[root@localhost ~]# mysql_config_editor print --all
[local]
user = root
password = *****
host = localhost
删除配置:
mysql_config_editor remove --login-path=test
使用login-path登录:
[root@localhost ~]# mysql --login-path=local
Warning: Using unique option prefix sock instead of socket is deprecated and will be removed in a future release. Please use the full name instead.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 13
Server version: 5.6.32-78.1-log Source distribution
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.
[root@localhost][(none)]>