参考文档:
https://mysql.net.cn/doc/refman/8.0/en/mysql-config-editor.html
OS上分别有2套库,设置后,通过不使用密码来登录,类似postgres的.pgpass文件
-- 执行一下命令,会要求提示输入密码
- mysql_config_editor set --login-path=3306 --user=root --host=127.0.0.1 --port=3306 --password
- mysql_config_editor set --login-path=3307 --user=root --host=127.0.0.1 --port=3307 --password
-- 产生的.mylogin.cnf文件,这是一个隐藏文件 ,而且不是文本格式的,所以打开会是乱码
- [root@redhat762100 ~]# more .mylogin.cnf
- �ԋu����>���J
--通过print打印出分组3306,分组3307,以及所有的内容
- [root@redhat762100 ~]# mysql_config_editor print --login-path=3306
- [3306]
- user = root
- password = *****
- host = 127.0.0.1
- port = 3306
- [root@redhat762100 ~]# mysql_config_editor print --login-path=3307
- [3307]
- user = root
- password = *****
- host = 127.0.0.1
- port = 3307
- [root@redhat762100 ~]#
-
- [root@redhat762100 ~]# mysql_config_editor print --all
- [3306]
- user = root
- password = *****
- host = 127.0.0.1
- port = 3306
- [3307]
- user = root
- password = *****
- host = 127.0.0.1
- port = 3307
- [root@redhat762100 ~]#
-- 通过免密码登录到3306库
- [root@redhat762100 ~]# mysql --login-path=3306
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 30
- Server version: 5.7.25-log MySQL Community Server (GPL)
-
- Copyright (c) 2000, 2019, 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.
-
- root@db 15:27: [(none)]>
-- 通过免密码登录到3307库
- [root@redhat762100 ~]# mysql --login-path=3307
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 12
- Server version: 5.7.25-log MySQL Community Server (GPL)
-
- Copyright (c) 2000, 2019, 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.
-
- root@db 15:27: [(none)]>
END