我有一個腳本文件,它可以立即備份伺服器的文檔根目錄和資料庫,並將其複製到我的終端系統,我從該終端系統透過 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 將提示輸入密碼。