让我的 Linux (Ubuntu) 询问我 SQL 密码是什么,这样我就不会将其存储在 .sh 文件中?

让我的 Linux (Ubuntu) 询问我 SQL 密码是什么,这样我就不会将其存储在 .sh 文件中?

我有一个脚本文件,它可以立即备份服务器的文档根目录和数据库,并将其复制到我的终端系统,我从该终端系统通过 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 将提示输入密码。

相关内容