mysql_config_editor组件可以给指定的连接和密码生成一个加密文件 .mylogin.cnf,默认位于当前用户home目录下。通过该文件可以使用mysql,mysqladmin等直接 免密登录,避免明文密码出现在脚本和/etc/my.cnf配置文件中。 官方文档 https://dev.mysql.com/doc/refman/5.7/en/mysql-config-editor.html 查看当前login path 文件( .mylogin.cnf)内容
# mysql_config_editor print --all
创建一个login到 login path 文件,第一次需输入密码
# mysql_config_editor set --login-path=myroot3306 --user=root --socket=/var/lib/mysql/mysql.sock --password Enter password:
再次查看 login path 文件
# mysql_config_editor print --all [myroot3306] user = root password = ***** socket = /var/lib/mysql/mysql.sock]
OS级别查看
# ll ~/.mylogin.cnf -rw------- 1 root root 152 Apr 20 16:46 /root/.mylogin.cnf # cat ~/.mylogin.cnf 是一些加密内容,乱码
测试登录
# mysql --login-path=myroot3306
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 18914 Server version: 5.7.21-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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. mysql>
删除一个login
# mysql_config_editor remove --login-path=myroot3306 # mysql_config_editor print --all
