當從數據庫導出數據或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管用
更多的解決辦法見如下: