%20%E8%A9%A2%E5%95%8F%E6%88%91%20SQL%20%E5%AF%86%E7%A2%BC%E6%98%AF%E4%BB%80%E9%BA%BC%EF%BC%8C%E9%80%99%E6%A8%A3%E6%88%91%E5%B0%B1%E4%B8%8D%E6%9C%83%E5%B0%87%E5%85%B6%E5%84%B2%E5%AD%98%E5%9C%A8%20.sh%20%E6%AA%94%E6%A1%88%E4%B8%AD%EF%BC%9F.png)
我有一個腳本文件,它可以立即備份伺服器的文檔根目錄和資料庫,並將其複製到我的終端系統,我從該終端系統透過 SSH 隧道連接到我的伺服器環境:
(
cd /var/www/html
zip -r ./html.zip ./
mysqldump -u USER -p PASSWORD --all-databases > ./db.sql
zip backup.zip html.zip db.sql
scp backup.zip /home/user/backups
rm ./html.zip ./db.sql ./backup.zip
)
我的問題:
在“密碼”處,我需要手動輸入密碼。這是我想要避免的事情,因為我已將此密碼內化到我的腦海中並且也經常使用它,並且不想在腳本中輸入它。
我的理想:
我寧願每次執行以下命令(或類似命令)時都提示輸入密碼:
mysqldump -u USER --all-databases > ./db.sql
我的問題:
透過 Linux 本身或透過某些現有的實用程式可以有這樣的提示嗎?
答案1
來自 mysqldump 線上說明頁:
o --password[=password], -p[password]
The password to use when connecting to the server. If you use the short option form (-p), you cannot have a space between the option and the password. If you omit the password value following the
--password or -p option on the command line, mysqldump prompts for one.
Specifying a password on the command line should be considered insecure. You can use an option file to avoid giving the password on the command line.
只要省略標誌中的密碼值-p
,mysqldump 將提示輸入密碼。