在批处理文件中提供 MySQL 密码的安全方法

Secure way of providing MySQL password in a batch file

我们有一个批处理文件,其中包括执行一些数据库操作。为了保持非交互性,目前我们在命令行上传递数据库用户 ID 和密码信息。我们不断收到以下警告消息:
Using a password on the command line interface can be insecure.

请建议如何将数据库密码信息传递给批处理文件,以使其保持非交互式但安全。

将密码放入选项文件,并在批处理文件中为您的 MySQL 客户端指定选项文件名。

假设您编辑了一个选项文件并将其命名为“myoptions.ini”。选项文件内容可能如下所示:

[client]
user = sandeep
password = ********

那么您的命令将如下所示:

mysql --defaults-file myoptions.ini -h <host> <database> -e <query>

https://dev.mysql.com/doc/refman/8.0/en/option-files.html