I am running a mysqldump via a bash script and have encountered a problem with a password that contains special characters.
mysqldump -hlocalhost -uUSERNAME -pPA$$W0RD DATABASE |
gzip > /home/USERNAME/backups-mysql/BACKUP.gz
How do I escape the password?
Even better, don't put the username or password on the command line where it can be seen by anyone who can do
ps -ef
.Create a control file named something like
/etc/mysqldump.cnf
:...where
client
is literal (not the name of your server) andYOUR_MYSQL_ROOT_PASSWORD
is... well... your mysql root password.Then invoke like this:
Personally my invocation is more like this:
I've never figured out how to use a similar
--defaults-file
parameter for mysql, however since this command runs fairly quickly the risk of exposure is much lower... although really that should be fixed.It works?