『Devil May Cry 5 Special Edition』登陸PlayStation®5   腦裡全都是結衣BB…Nintendo Switch的2020冬季版電視廣告公開   東京電玩展 2020 Online節目時間表   Sa·Ga系列30週年最後大發表!《SaGa Frontier Remastered》發售確定!   提瓦特大陸上的精彩冒險,從今天開始   PS Store春季優惠正式開跑!最大折扣2折(80%OFF)起   遊戲指南教你如何在《Demon’s Souls》的初期生存下來   《Returnal》將於2021年3月19日登陸PS5 

MySQL 使用 mysql_config_editor 避免 CLI 出現密碼

MySQL 在 Bash Shell、Script 執行,若有密碼直接打在命令列裡面,都會出現下述的警告 (Warning):

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

為何會有這個警告呢?

主要是平常 CLI 的命令,用 ps 都可以查看到,若密碼打在上面,密碼很容易就因此洩漏出去(不過 MySQL 新版有避免這個問題,密碼直接輸入,於 ps 是看不到密碼的)。

當然除了 ps 外,還有很多方法可以查看,在此就不繼續探討。

MySQL 使用 mysql_config_editor 避免 CLI 出現密碼

上述講到的 Warning,MySQL 為了解決此問題,有做一個 mysql_config_editor,會將主機的 host、帳號、密碼 等資訊存入並加密(AES ECB),直接使用來登入,相對會安全很多,此篇主要來介紹 mysql_config_editor 的幾個用法。

下述範例與資料整理自官方文件:

一般設定檔內容:(此篇會用此設定檔當範例來設定 mysql_config_editor)

[client]
user = localuser
password = localpass
host = localhost
[remote]
user = remoteuser
password = remotepass
host = remote.example.com

新增 mysql_config_editor 設定

將上述設定檔,設定入 mysql_config_editor

  1. $ mysql_config_editor set –login-path=client –host=localhost –user=localuser –password Enter password: 輸入 “localpass”
  2. $ mysql_config_editor set –login-path=remote –host=remote.example.com –user=remoteuser –password Enter password: 輸入”remotepass”
  3. $ mysql_config_editor set –login-path=127.0.0.1 –host=127.0.0.1 –user=root –port=3306 –password
  4. ls ~/.mylogin.cnf # 可以看到此檔案,less 看都會是 binary
  5. $ mysql_config_editor print –all # 查看所有設定,密碼不會直接呈現 [client] user = localuser password = host = localhost [remote] user = remoteuser password = host = remote.example.com

使用 mysql_config_editor 登入、操作 SQL 命令

移除 mysql_config_editor 設定檔

MySQL 5.7 標準 Client 的 mysql_config_editor 位置

至於使用 Percona 的話,5.6 版有 mysql_config_editor,5.7 版卻沒有,要怎麼解決呢?

找 Percona 的 mysql_config_editor 套件在哪裡

  1. dpkg -S mysql_config_editor # 找是哪個 package percona-server-client-5.6: /usr/share/man/man1/mysql_config_editor.1.gz percona-server-client-5.6: /usr/bin/mysql_config_editor
  2. sudo apt install percona-server-client # 若是 Percona 5.6 可以這樣查詢、安裝

Percona client 5.7 卻沒有 mysql_config_editor 的解法

相關網頁

相關文章