Warning: Using a password on the command line interface can be insecure.
上面的提示是当你在命令行输入mysql 密码登录时出现的提示,但有些自动批处理任务是需要使用密码的,有什么办法不提示?
这个提示也是mysql 5.6.x之后版本的提示,可以使用mysql_config_editor配置登录参数
mysql_config_editor set --login-path=local --host=localhost --user=username --password
这样就可以使用下面的命令代替之前的老方法了(注意--login-path要排在其它参数前面)
mysql --login-path=local -e "statement"
密码加密后保存在 $HOME/.mylogin.cnf
查看
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
参考
http://dev.mysql.com/doc/refman/5.7/en/mysql-config-editor.html