消除MySQL連接時的Warning:Using a password on the command line interface can be insecure.


MySQL5.6之后的版本在通過客戶端連接或者備份時時都會有出現如下的一個警告:

Warning: Using a password on the command line interface can be insecure.

在一些腳本操作中可能會造成一些干擾,這里介紹下兩種方式來避免這個輸出。

1:修改配置文件
vim /etc/mysql/my.cnf
在[client]下添加
user=***
password=***
保存退出,重啟mysql進程;
此時再次連接MySQL的時候,不要在命令行出現-u -p參數,直接mysql:
root@ubuntu:/etc/mysql/mysql.conf.d# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1637
Server version: 5.7.31-0ubuntu0.16.04.1 (Ubuntu)

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>
可以看到之前的警告就沒有了!
注意:如果你是使用mysqldump指令去連接,就修改配置文件中[mysqldump]的部分。

2:重定向警告

root@ubuntu:/etc/mysql/mysql.conf.d# mysql -usaier -plr@2018 2>/dev/null
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1640
Server version: 5.7.31-0ubuntu0.16.04.1 (Ubuntu)

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>
 
通過這種方式,我們把告警輸出重定向到/dev/null,告警就不會輸出到交互式界面了,同時腳本里也會獲得一個比較純凈的返回家過變量。
 
這兩種方式,第一種需要改配置文件,而且任何人都可以不需要密碼直接進入BD,存在一定的風險性;
第二種需要重定向錯誤和告警輸出,這樣會讓我們忽略掉一些異常信息,因此這兩種方式需要酌情選擇。
 
以上。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM