例如测试环境在服务端登陆想要偷懒,就会想要直接免密登录
方式1
之前我们配置免密都是放在配置文件中[client]标签中配置的,这个问题就在于是明文的
[client]
user=root
password=123456
port = 3306
方式2
而有些小伙伴知道加载特性可能会藏的深一些,可能有些小伙伴会配置到/usr/local/mysql/etc/my.cnf 或 ~/.my.cnf中去,但还是明文记录的
# 加载顺序,后面补充或覆盖前面的参数
[root@yq ~]# mysql --help |grep my.cnf
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
方式3【推荐】
创建登陆路径
mysql_config_editor set --login-path=client --host=localhost --user=root --password
mysql_config_editor set --login-path=mypath --host=127.0.0.1 --user=ytest --password
查看当前配置的路径
[root@testinit ~]# mysql_config_editor print --all
[client]
user = root
password = *****
host = localhost
[mypath]
user = root
password = *****
host = localhost
登陆
mysql --login-path=client # 由于和配置文件的[client]一直,因此这个等同于直接执行 mysql 即可
mysql --login-path=mypath
移除
mysql_config_editor remove --login-path=mypath