暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL用户设置密码后,如何免密登陆?

原创 Shubing Wu 2022-06-08
1412

MySQL用户设置密码后,如何免密登陆?三个地方可以用来存储用户的mysql凭据,如下:

1、配置.my.cnf文件
su - mysql
vi .my.cnf
添加如下内容:
[client]
host=localhost
user=scott
password=123

每次登陆MySQL的交互界面,只需键入mysql命令,便可默认将host,user,password的值根据~/.my.cnf中的内容传给mysql命令,进行mysql的登陆操做。

2、配置my.cnf
#修改配置文件
$ cat /etc/my.cnf
...
[client] #注意账号密码需要写在此标签下
user=root
password=123

3、mysql_config_editor配置.mylogin.cnf

语法:
mysql_config_editor set --user=scott --password --host=<host>
1)创建一个mylogin.cnf文件
$su -mysql
$mysql_config_editor set --user=scott --password

2)文件创建成功:
$ ls -la .mylogin.cnf
-rw------- 1 mysql mysql 100 Jun 8 09:21 .mylogin.cnf

$ mysql_config_editor print --all
[client]
user = scott
password = *****

尝试登录:
$ mysql --socket=/u01/mysql8/db_home/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
.....
mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| scott@% |
+----------------+
1 row in set (0.00 sec)

最后修改时间:2022-06-08 09:31:10
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论