简体   繁体   中英

Shell script with mysqldump

I wrote a shell script to automate mysqldump. I don't want my password to be entered in the script file. Can anyone suggest me an alternative way to do this?

If you are running the script interactively, then you can use read to read the password into an environmental variable, and then echo that password to mysqldump.

read -s -p 'password: ' password

echo "$password" | mysqldump ...

The password will be stored in plain text in memory but not elsewhere.

Alternatively as per the documentation you can use an option file to avoid giving the password on the command line. The file would contain something similar to the below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM