您的自動執行的MySQL批次作業是如何登入MySQL的?將密碼寫入脚本?還是到一個存有密碼的檔案裡去讀取?您是否曾經為了設法符合公司規定的不能以明碼的型式保存密碼而傷腦筋?MySQL有一個較不為人所知的程式-mysql_config-editor(在MySQL的bin目錄下能找到它)能為您解決這個問題,做法如下:
1.
建立login path: ./bin/mysql_config_editor
set --login-path='mysql-cli' --user='root' --host='127.0.0.1' --port=3306
–password
l
建一個名為mysql-cli的login path,它會在user的目錄之下建一個名為.mysql_config.cnf的加密檔案,當您type它時只能看到亂碼
2.
如果想要查有那些login path,它們的參數為何,可以用以下指令 :
./bin/mysql_config_editor print --all
[root@localhost:33060]
user = root
password = *****
host = localhost
port = 33060
[mysql-cli]
user = root
password = *****
host = 127.0.0.1
port = 3306
您能看到所有的連線參數,但密碼都是”*”
3. 登入MySQL時只要指定login
path就行了
./bin/mysql --login-path='mysql-cli' sys
Reading table information for completion of
table and column names
You can turn off this feature to get a
quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.16-commercial MySQL
Enterprise Server - Commercial
Copyright (c) 2000, 2019, Oracle and/or its
affiliates. All rights reserved.
Oracle is a registered trademark of Oracle
Corporation and/or its
affiliates. Other names may be trademarks
of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to
clear the current input statement.
root@localhost:3306[sys]>
登登... !!! 不用打密碼 進入資料庫😄
當然,您必需要好好保護這個.mylogin.cnf檔,因為任何人拿到它都可以用root登入資料庫😨