Centos下_MysqL5.7在使用mysqldump命令備份資料庫報錯:mysqldump: [Warning] Using a password on the command line interface can be insecure.

OldBoy~發表於2017-11-14

在阿里雲伺服器增加一個shell指令碼定時備份資料庫指令碼執行任務時,測試性的執行了備份命令,如下

[root@iZ2ze503xw2q1fftv5rhboZ mysql_bak]# /usr/local/mysql/bin/mysqldump -uroot -pmyServerPwd# dateabase > /data/mysql_bak/bak_test.sql

在執行完了命令本該在指定的目錄下出現bak_test.sql檔案,然而並沒有生成,報了一行錯誤。這個問題應該是在MySQL5.6+版本的時候就有出現,可能是為了確保資料庫的安全性採用的保護機制。

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

網上大部分給出的解決方案都是修改mysql的配置檔案,給[client]選項增加三行命令

vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
host = localhost        //地址
user = root            //使用者
password = 'myServerPwd'    //密碼

在增加了三行程式碼,我習慣性的重啟了mysql服務,再同樣執行備份命令,發現還是出現錯誤。

在搜尋各種方案的過程中也無意中發現關於此方法在安全性上的一些官方性不足,mysql的官方給出的說明。

https://dev.mysql.com/doc/refman/5.6/en/password-security-user.html?spm=5176.7737807.2.3.D6p7hh

然後針對高版本Mysql備份資料庫的解決方案來了,前方高能~~~

命令和以前常用的快速匯入和匯入命令有所不同了,需要載入我們配置的MYSQL配置檔案!

/usr/local/mysql/bin/mysqldump --defaults-extra-file=/etc/my.cnf database > /data/mysql_bak/bak_test.sql    //備份匯出資料庫
/usr/local/mysql/bin/mysql --defaults-extra-file=/etc/my.cnf database < test_db.sql          //匯入資料庫

 檢視/data/mysql_bak下,發現想要的資料庫備份檔案出現了~

相關文章