以往在備份 MySQL 的時候,都會把密碼寫在 script 裡頭,基本上就不安全。從某天開始 Bash shell scipt 就會跳出警告 Warning: Using a password on the command line interface can be insecure
,雖然還是能夠執行備份,但是就覺得很毛,後來乾脆一次用 mysql_config_editor
修掉手邊所有的 backup script。
建立 mysql_config_editor 的 login-path
mysql_config_editor set --login-path=phpmyadmin --host=localhost --user=phpmyadmin --password
或是 root
mysql_config_editor set --login-path=root --host=localhost --user=root --password
密碼要自行輸入唷。
顯示已建立的 login-path
root@guestOS:~# mysql_config_editor print --all
[phpmyadmin]
user = phpmyadmin
password = *****
host = localhost
可以看到密碼被 ***** 了。
不用密碼使用 mysql
mysql --login-path=phpmyadmin
mysql_config_editor 相關使用方式
列出所有 login-path
mysql_config_editor print --all
清空 or 重設所有 login-path
mysql_config_editor reset
移除單一 login-path
mysql_config_editor remove --login-path=phpmyadmin