MySQL实现无密码登录(mysql_config_editor)


有一个业务需求是从一台主机上dump MySQL数据库的数据,但是又不想让业务人员知道具体MySQL用户的密码,可以用mysql_config_editor命令实现

一,测试环境
A机器IP为192.168.3.171
B机器IP为 192.168.3.173
打算实现无“密码”从B连接到A
A和B的数据库版本

  1. (root@localhost) [(none)]> select version();
  2. +------------+
  3. | version() |
  4. +------------+
  5. | 5.7.17-log |
  6. +------------+
  7. 1 row in set (0.00 sec)
二,在A机器上 创建测试用户并赋予权限

  1. (root@localhost) [(none)]> create user gl@'192.168.3.173' identified by 'onlygl';
  2. Query OK, 0 rows affected (0.00 sec)

  3. (root@localhost) [(none)]> grant all on *.* to gl@'192.168.3.173';
  4. Query OK, 0 rows affected (0.01 sec)
三,在B机器上执行如下命令,输入gl用户的密码

  1. mysql_config_editor set --login-path=gl --host=192.168.3.171 --user=gl --password
四,执行上面命令后,可以在home的目录下找到一个隐藏文件 .mylogin.cnf ,如下:

  1. -rw------- 1 root root 136 Feb 27 19:04 .mylogin.cnf
五,查看文件里的内容

  1. [root@mysqltest ~]# mysql_config_editor print --all
  2. [gl]
  3. user = gl
  4. password = *****
  5. host = 192.168.3.171
六,登录

  1. [root@mysqltest ~]# mysql --login-path=gl
  2. Welcome to the MySQL monitor. Commands end with ; or \g.
  3. Your MySQL connection id is 311
  4. Server version: 5.7.17-log Mysqlma
  5. Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
  6. Oracle is a registered trademark of Oracle Corporation and/or its
  7. affiliates. Other names may be trademarks of their respective
  8. owners.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. (gl@192.168.3.171) [(none)]>
七,如果不想用了,用如下命令删除

  1. mysql_config_editor remove --login-path=gl
八,适用范围

  1. mysql
  2. mysqladmin
  3. mysqldump
九,总结
1.显而易见的是用户密码被修改后,需要重新创建login-path
2.该功能仅仅在5.6.6以上版本才支持


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20893244/viewspace-2134390/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/20893244/viewspace-2134390/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值