MySQL命令行-u -p登陸時,會出現標黃字體的這種警告
[root@mysql02 ~]# mysql -uroot -p123456
一般有這幾種方式解決:
1.將密碼寫入到主配置文件中
[root@localhost ~]# vim /etc/my.cnf [mysqldump] user=root password=123456 [mysql] user=root password=123456
直接使用命令登錄,再也無需輸入賬號密碼
[root@mysql02 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.20 MySQL Community Server - GPL Copyright (c) 2000, 2020, 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>
2.自動配置MYSQL密文密碼
[root@localhost ~]# mysql_config_editor set --user=root --host=localhost --port=3306 --password Enter password: 輸入密碼
該操作會在用戶家目錄下生成一個隱藏文件".mylogin.cnf",里面記錄了MYSQL的密文的密碼,只要配置了以后,也是直接使用命令登錄,無需輸入賬號密碼了,如果想要取消,刪除此文件即可
3.直接使用命令登錄,屏蔽錯誤信息
[root@localhost ~]# mysql -uroot -p123456 2>/dev/null Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.20 MySQL Community Server - GPL Copyright (c) 2000, 2020, 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>
4.使用常量
將密碼設置為常量
export MYSQL_PWD=<password>
不清楚為什么必須要用MYSQL_PWD,用自定義就不行
使用如下,一般針對腳本:
[root@mysql02 ~]# export MYSQL_PWD=123456 [root@mysql02 ~]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.20 MySQL Community Server - GPL Copyright (c) 2000, 2020, 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>
這種方式就不用設置-p參數
腳本中也可以這樣寫。