设为首页 收藏本站
查看: 962|回复: 0

[经验分享] MySQL之mysql_config_editor使用

[复制链接]

尚未签到

发表于 2018-9-27 13:33:51 | 显示全部楼层 |阅读模式
  mysql_config_editor/login-path使用

一、设计缘由说明:
  login-path是MySQL5.6开始支持的新特性。通过借助mysql_config_editor工具将登陆MySQL服务的认证信息加密保存在.mylogin.cnf文件(默认位于用户主目录),
  之后,MySQL客户端工具可通过读取该加密文件连接MySQL,避免重复输入登录信息,避免敏感信息暴露。

二、工具使用帮助
  mysql_config_editor使用帮助:

2.1配置:
  

mysql_config_editor set --login-path=test --user=test_user  --host=127.0.0.1 --port=3306 --password  
或者
  
mysql_config_editor set -G test001 -uroot -p -hlocalhost -P3306 -S /tmp/mysql.sock
  
mysql_config_editor set -G test001 -uroot -p
  

  采用哪种方式,具体要根据my.cnf配置文件的中MySQL的登陆参数以及MySQL中的数据库的具体授权来设定
  其中可配置项介绍:
  

-h,–host=name 添加host到登陆文件中  
-G,–login-path=name 在登录文件中为login path添加名字(默认为client)
  
-p,–password 在登陆文件中添加密码(该密码会被mysql_config_editor自动加密)
  
-u,–user 添加用户名到登陆文件中
  
-S,–socket=name 添加sock文件路径到登陆文件中
  
-P,–port=name 添加登陆端口到登陆文件中
  

2.2、实例演示
  此处以MySQL的root登陆账户来实例演示:
  很多同学都是这样登陆MySQL的
  

[root@git-server ~]# mysql -uroot -p'wujianwei'  
工具使用
  
[root@git-server ~]# mysql_config_editor set --login-path=test001 --user=root  --host=localhost --port=3306 --password
  
Enter password:
  

  同时会在位于用户主目录生成一个加密的二进制文件
  

[root@git-server ~]# ll /root/.mylogin.cnf  
-rw------- 1 root root 156 Jul 21 10:36 /root/.mylogin.cnf
  
[root@git-server ~]#
  

  此时登陆MySQL截图演示:
DSC0000.jpg

  或者以下的方式也是可以的:
  

[root@git-server ~]# mysql_config_editor set -G test001 -uroot -hlocalhost -P3306 -S /tmp/mysql.sock -p  
Enter password:
  
[root@git-server ~]# ll .mylogin.cnf
  
-rw------- 1 root root 192 Jul 21 11:05 .mylogin.cnf
  

2.3显示配置:
  

mysql_config_editor print --login-path=test #显示执行的login-path配置  
mysql_config_editor print --all             #显示所有的login-path信息
  

  实例演示:
  

[root@git-server ~]# mysql_config_editor print --login-path=test001  
[test001]
  
user = root
  
password = *****
  
host = localhost
  
socket = /tmp/mysql.sock
  
port = 3306
  

  查看指定的登陆名称登陆信息:
  

[root@git-server ~]# mysql_config_editor print -Gtest001  
[test001]
  
user = root
  
password = *****
  
host = localhost
  
socket = /tmp/mysql.sock
  
port = 3306
  

[root@git-server ~]# mysql_config_editor set -G test002 -uroot -hlocalhost -P3306 -S /tmp/mysql.sock -p  
Enter password:
  
[root@git-server ~]# mysql_config_editor print -Gtest002
  
[test002]
  
user = root
  
password = *****
  
host = localhost
  
socket = /tmp/mysql.sock
  
port = 3306
  

  查看所有的登陆名称的登陆信息:
  

[root@git-server ~]# mysql_config_editor print --all  
[test001]
  
user = root
  
password = *****
  
host = localhost
  
socket = /tmp/mysql.sock
  
port = 3306
  
[test002]
  
user = root
  
password = *****
  
host = localhost
  
socket = /tmp/mysql.sock
  
port = 3306
  

2.4删除配置:
  mysql_config_editor remove --login-path=test
  

[root@git-server ~]# mysql_config_editor remove --login-path=test002  
或者是:
  
[root@git-server ~]# mysql_config_editor remove -Gtest002
  
[root@git-server ~]# mysql_config_editor print --all
  
[test001]
  
user = root
  
password = *****
  
host = localhost
  
socket = /tmp/mysql.sock
  
port = 3306
  

  重置配置:
  mysql_config_editor reset --login-path=test

2.5、采用默认的登陆方式
  

[root@git-server ~]#mysql_config_editor set -uroot -p  
[root@git-server ~]# mysql_config_editor print --all
  
[test001]
  
user = root
  
password = *****
  
host = localhost
  
socket = /tmp/mysql.sock
  
port = 3306
  
[client]
  
user = root
  
password = *****
  

  登陆截图:
DSC0001.jpg


2.6其中可删除项介绍
  -h,–host=name 添加host到登陆文件中
  -G,–login-path=name 在登录文件中为login path添加名字(默认为client)
  -p,–password 在登陆文件中添加密码(该密码会被mysql_config_editor自动加密)
  -u,–user 添加用户名到登陆文件中
  -S,–socket=name 添加sock文件路径到登陆文件中
  -P,–port=name 添加登陆端口到登陆文件中

2.7、远程登陆其他机器的MySQL
  若要登录其他主机、其他端口,或者添加其他额外参数,直接在上述命令后添加即可
  

shell>mysql --login-path=test  -h host1 -P port1 #登录host1:poet1上的MySQL  
shell>mysql --login-path=test  -h host1 -P port1 test_db #登录host1:poet1上的MySQL中的test_db库
  

  参考地址:
  http://dev.mysql.com/doc/refman/5.7/en/mysql-config-editor.html



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-602864-1-1.html 上篇帖子: Flash+PHP+MySQL留言板教程 下篇帖子: CentOS5+mysql+php的配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表