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

相关文章
相关标签/搜索