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

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

 

來自TMySQL用戶,包括不少開發和GCS系統,都習慣mysql –u$USER –p$PASSWD 來執行,這條命令在MySQL 5.6會有個warning告警:html

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


單據或者腳本解析到這個warning,則所有失敗。sql

因此,爲了向前兼容,咱們在源碼層面將這個warn關閉。數據庫

322300024e3d55e3a6ca




今天老左有在幫一個網友搬家網站過程當中,習慣導出MySQL數據庫的時候採用mysqldump命令,可是意外發生了出現"Warning: Using a password on the command line interface can be insecure."的錯誤提示,固然數據庫確定也沒有能備份下來。這個問題應該是在MySQL5.6+版本的時候就有出現,多是爲了確保數據庫的安全性採用的保護機制。vim

遇到問題那就去解決問題,大概搜索到國內的一些網站,大部分都是複製的,也沒有講的明白,因而仍是找老外的信息,因而老左就整理到下面比較全的方法且通過驗證是沒有問題的。安全

第一種方法、修改數據庫配置文件ide

一、咱們須要修改數據庫配置文件,這個要看咱們數據庫的配置的,有些是在/etc/my.cnf,有些是/etc/my.conf測試

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

咱們須要在[client]部分添加腳本:網站

host=localhost
user=數據庫用戶
password='數據庫密碼'ui

這裏參數要修改爲咱們本身的。

二、採用命令導出和導入數據庫

其實在這個時候,咱們若是採用"詳解使用mysqldump命令備份還原MySQL數據用法整理"介紹的方法也是可使用的,雖然依舊有錯誤提示,可是數據庫仍是能夠導出的。您確定和老左同樣是追求細節的人,一點點問題都不能有,但咱們能夠用下面的命令導出和導入,就沒有錯誤提示。

#導出數據庫

mysqldump --defaults-extra-file=/etc/my.cnf database > database.sql

#導入數據庫

mysql --defaults-extra-file=/etc/my.cnf database < database.sql

這裏咱們能夠看到上面的命令和之前經常使用的快速導入和導入命令有所不一樣了,須要加載咱們配置的MYSQL配置文件,這個紅色部分要根據咱們實際的路徑修改。用這樣的命令導出備份和導入是沒有錯誤提示的。

第二種方法、利用mysql_config_editor

一、設置加密模式

mysql_config_editor set --login-path=local --host=localhost --user=db_user --password

紅色部分是須要修改爲咱們本身數據庫用戶名的,回車以後會提示咱們輸入數據庫密碼,咱們照樣輸入。

二、執行備份

mysqldump -u db_user -pInsecurePassword my_database | gzip > backup.tar.gz

根據咱們數據信息修改用戶和用戶名和數據庫密碼,執行備份,這裏老左測試仍是有錯誤提示,但數據庫是能夠備份的。

總之,咱們只要實現結果,能夠選擇以上2種方法其一操做,固然老左也有看到其餘的方法,這裏就很少分享了,若是有興趣的能夠搜索其餘解決方法。




1.最近把MySQL從5.5升到5.6之後,mysqldump竟然很差用了,提示:

 代碼以下

複製代碼

[root@qttc ~]# /usr/local/mysql/bin/mysqldump  -uroot -proot db > bak.sql
Warning: Using a password on the command line interface can be insecure.

翻譯過來是:在命令行界面上使用密碼能夠是不安全的;

這讓人有點鬱悶,5.5用的1直都很爽,到5.6竟然說命令行方式寫密碼不安全?那密碼寫哪呢?

在官網文檔找到了原因,你們能夠點擊這裏看看:

1.官方網址:http://dev.mysql.com/doc/refman/5.1/en/password-security-user.html

MySQL users shoulduse the following guidelines to keep passwords secure.

   When you run a client program to connect to the MySQL server, it is inadvisableto specify your password in a way that exposes it to discovery by other users.The methods you can use to specify your password when you run client programsare listed here, along with an assessment of the risks of each method. Inshort, the safest methods are to have the client program prompt for thepassword or to specify the password in a properly protected option file.

翻譯過來大意是在命令行下若是要使用密碼能夠在執行命令後的提示輸入裏輸入密碼,或者在指定的安全文件內指定密碼;那安全文件時哪一個呢?文檔對此給出了答案:

Store your passwordin an option file. For example, on Unix, you can list your password in the[client] section of the .my.cnf file in your home directory:

能夠在my.cnf內指定,因而打開個人my.cnf,在[mysqldump]下增長:

 代碼以下

複製代碼

user=root
password=root

文中說的在[client]下面加也能夠,但那樣就全部塊的操做都能共享了,因此生產環境上爲了安全仍是儘可能分開;保存退出再dump就ok了;

 代碼以下

複製代碼

[root@qttc ~]# /usr/local/mysql/bin/mysqldump db > bak.sql
[root@qttc ~]#

MySQL 5.6 警告信息 command line interface can be insecure 修復

在命令行輸入密碼,就會提示這些安全警告信息;

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

注:mysql -u root -pPASSWORD 或 mysqldump -u root -pPASSWORD 都會輸出這樣的警告信息.

1.針對mysql:

mysql -u root -pPASSWORD改爲mysql -u root -p 在輸入密碼便可.

2.mysqldump就比較麻煩了,一般都寫在scripts腳本中;

解決方法:

對於mysqldump 要如何避免出現(Warning:Using a password on the command line interface can be insecure.) 警告信息呢?

vim /etc/mysql/my.cnf

[mysqldump]

user=your_backup_user_name

password=your_backup_password

修改完配置文件後, 只須要執行mysqldump 腳本就能夠了;備份腳本中不須要涉及用戶名密碼相關信息;

相關文章
相關標籤/搜索