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)




