Warning: Using a password on the command line interface can be insecure解决办法

当从数据库导出数据或mysqldump的时候,在mysql5.6.x以上版本会报Warning: Using a password on the command line interface can be insecure 错误,虽然不影响使用,但是还是挺烦人的。

比如在shell中执行如下导出语句

echo "select * from test limit 10 " | sh datamysql.sh > test.txt 

其中datamysql.sh文件内容如下:

mysql -h 127.0.0.1 -P xxxx -u test -pxxxx testdatabase -A

执行完之后能正常导出,但是针对这个错误解决办法如下:

echo "select * from test limit 10 " | mysql --defaults-file=/path/to/config.cnf testdatabase  > test.txt 

其中config.cnf内容如下

[client]
host=127.0.0.1
user=test
password=xxxxxxx
port=xxxx

 

报上述错误的原因是密码不能直接暴露在命令行中不安全

在查资料解决时,有时是 --default-extra-file 但我的使用 --defaults-file管用

更多的解决办法见如下:

https://stackoverflow.com/questions/20751352/suppress-warning-messages-using-mysql-from-within-terminal-but-password-written


 

posted @ 2020-04-28 15:36  枯木逢春  阅读(11967)  评论(0编辑  收藏  举报