Mysqldump without password in crontab

I am trying to backup my database using mysqldump and cronjobs.

Well, I added the following command to the crontab root of the user:

*/30 * * * * mysqldump -u root -pVERYSECUREPASSWORD --all-databases > /var/www/cloud/dump_komplett.sql &> /dev/null 

So far this works, but the problem is that the password is specified in this command.

So, I want to include a .database.cnf file that looks like this:

 [mysqldump] user=root password=VERYSECUREPASSWORD 

and changed the mysqldump command to

 mysqldump --defaults-extra-file="/var/crons/mysql/.database.cnf" --all-databases -u root > /var/www/cloud/dump_komplett.sql 

to solve this problem.

But this command does not work with an error:

 mysqldump: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect 

I do not know what happened.

Here are a few commands I have also tried:

 mysqldump --defaults-extra-file="/var/crons/mysql/.database.cnf" --all-databases > /var/www/cloud/dump_komplett.sql mysqldump --defaults-file="/var/crons/mysql/.database.cnf" --all-databases > /var/www/cloud/dump_komplett.sql mysqldump --defaults-file="/var/crons/mysql/.database.cnf" --all-databases -u root > /var/www/cloud/dump_komplett.sql 
Content

and .database.cnf I also tried:

 [client] user=root password=VERYSECUREPASSWORD [mysqldump] host=localhost user=root password=VERYSECUREPASSWORD [client] host=localhost user=root password=VERYSECUREPASSWORD 
+7
mysql cron crontab mysqldump backup
source share
2 answers

The user must be specified in the command, and not in the file with the u parameter.

For more on scheduling cron jobs using mysqldump , check this answer

+5
source share

I found out that the password must be between quotation marks

 [client] user=root password="VERYSECUREPASSWORD" 

It's time to figure out why it doesn't work with passwords with lots of non-alphabetic characters

+2
source share

All Articles