有一个业务需求是从一台主机上dump MySQL数据库的数据,但是又不想让业务人员知道具体MySQL用户的密码,可以用mysql_config_editor命令实现
一,测试环境
A机器IP为192.168.3.171
B机器IP为 192.168.3.173
打算实现无“密码”从B连接到A
A和B的数据库版本
- (root@localhost) [(none)]> select version();
- +------------+
- | version() |
- +------------+
- | 5.7.17-log |
- +------------+
- 1 row in set (0.00 sec)
- (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)
- mysql_config_editor set --login-path=gl --host=192.168.3.171 --user=gl --password
- -rw------- 1 root root 136 Feb 27 19:04 .mylogin.cnf
- [root@mysqltest ~]# mysql_config_editor print --all
- [gl]
- user = gl
- password = *****
- host = 192.168.3.171
- [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 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.
- (gl@192.168.3.171) [(none)]>
- mysql_config_editor remove --login-path=gl
- mysql
- mysqladmin
- mysqldump
1.显而易见的是用户密码被修改后,需要重新创建login-path
2.该功能仅仅在5.6.6以上版本才支持
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20893244/viewspace-2134390/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/20893244/viewspace-2134390/