faith丶

导航

mysql本地指定--login-path免密登录(mysql_config_editor的用法)

###

1、前言

我们通常登陆mysql都是用如下命令登陆,命令很长而且密码如果超级复杂的话,每次登陆还要输入密码;复杂的密码不仅难记,还容易输错,非常蛋疼 
mysql_config_editor这个命令就为我们解决了这一蛋疼的问题 正常登陆方法: mysql
-uroot -p -S /tmp/mysql3306.sock

2、生成一个mylogin.cnf文件

[root@zw-test-db /]# mysql_config_editor set --login-path=dev-mysql-01 --user=root --socket=/tmp/mysql3306.sock --password
Enter password: 

[root@zw-test-db mysql]# cat ~/.mylogin.cnf 

^@^@^@^@^]^E^\^M^]^X^Z^O^A^W^D^A^A^W^C^L^Z^Q^V^O^P^@^@^@E8¼é$Go¾Ò^]<99>
SgO^P^@^@^@ÏC:@}w½öètËíRÁWK ^@^@^@^A"p9<86>^\+ñ7GìÞ<80>ZP<9a>¾tLÆø<86>·<34<81>­þe<91>^T ^@^@^@p} Qý1ÛÀk<86>b!<96>ªP^Rå<87>^_Õ~åºt <89>÷á|Ü<82>²

可以看到一串加密的文件

3、打印一下生成文件的内容

[root@zw-test-db ~]# mysql_config_editor print --all
[dev-mysql-01]
user = root
password = *****
socket = /tmp/mysql3306.sock

4、用加密文件登陆

[root@zw-test-db ~]# mysql --login-path=dev-mysql-01
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.14-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> 

以后登陆就不用输入超长的密码啦!



原文链接:https://blog.csdn.net/zhengwei125/article/details/52414284

###

posted on 2021-12-07 18:02  faith丶  阅读(706)  评论(0编辑  收藏  举报