在命令行执行mysql的命令mysql -uroot -p${password} < file.sql,会导致下面的警告:

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

意思就是在命令行使用密码明文不安全。但有的时候,我就是需要在命令行这样执行sql脚本啊,显示这个警告看着很不舒服,怎么不让mysql显示这个警告呢。

在 stackoverflow上找到这篇文章,给出了少解决办法

《Suppress warning messages using mysql from within Terminal, but password written in bash script》

其中我觉得最方便就是利用MYSQL_PWD传递密码,使用方法如下:

export MYSQL_PWD=${password}
mysql -uroot -p${password} < file.sql

MYSQL_PWD=${password} && mysql -uroot -p${password} < file.sql
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐