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

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM