gpt4 book ai didi

bash - 带有 mysqldump 的 shell 脚本

转载 作者:行者123 更新时间:2023-11-29 11:49:28 25 4
gpt4 key购买 nike

我编写了一个 shell 脚本来自动化 mysqldump。我不希望在脚本文件中输入我的密码。谁能建议我另一种方法来做到这一点?

最佳答案

如果您以交互方式运行脚本,则可以使用 read 将密码读取到环境变量中,然后将该密码回显到 mysqldump。

read -s -p 'password: ' password

echo "$password" | mysqldump ...

密码将以纯文本形式存储在内存中,但不会存储在其他地方。

或者按照the documentation您可以使用 option file以避免在命令行上输入密码。该文件将包含类似于以下内容的内容:

[client]
# The following password will be sent to all standard MySQL clients
password="my_password"

关于bash - 带有 mysqldump 的 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34377880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com