MySQL命令行不輸入密碼的安全方式

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

上面的提示是當你在命令行輸入mysql 密碼登陸時出現的提示,但有些自動批處理任務是須要使用密碼的,有什麼辦法不提示?html

這個提示也是mysql 5.6.x以後版本的提示,可使用mysql_config_editor配置登陸參數mysql

mysql_config_editor set --login-path=local --host=localhost --user=username --password

這樣就可使用下面的命令代替以前的老方法了(注意--login-path要排在其它參數前面)sql

mysql --login-path=local  -e "statement"

密碼加密後保存在 $HOME/.mylogin.cnf安全

查看bash

mysql_config_editor print --all

 另一種不太安全但也不用輸入密碼的方法是使用.my.cnf的配置,如加密

$ cat > $HOME/.my.cnf
[client]
user = scott
password = tiger
host = mydbserver
^D

或者這樣命令行

mysqladmin -uxxx -pxxx ping 2>/dev/null

參考code

http://dev.mysql.com/doc/refman/5.7/en/mysql-config-editor.htmlserver

相關文章
相關標籤/搜索