Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysqldump without password in crontab

I try to backup my database with mysqldump and cronjobs.

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

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

This works fine so far, but the problem is that the password is set in this command.

So I want to include a .database.cnf file that look 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 fails with the error:

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

I don't know what's wrong.

Here are some commands I 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

and .database.cnf contents I also tried:

[client]
user=root
password=VERYSECUREPASSWORD

[mysqldump]
host=localhost
user=root
password=VERYSECUREPASSWORD

[client]
host=localhost
user=root
password=VERYSECUREPASSWORD
like image 561
Marcel Balzer Avatar asked Nov 11 '13 11:11

Marcel Balzer


People also ask

Does MySQLdump lock tables?

By default, mysqldump locks all the tables it's about to dump. This ensure the data is in a consistent state during the dump.

Why is Mysqldump not working?

If mysqldump is not identified by the cmd prompt that means it cannot recognize where the mysqldump.exe is located. You need to add path of the directory where the exe is located in the PATH variable under environment variables. After doing that your command will start working in the cmd prompt.

Which of the following commands can be used to dump the first 5 rows of a table from your database in MySQL command line interface of Cloud IDE?

mysqldump can retrieve and dump table contents row by row, or it can retrieve the entire content from a table and buffer it in memory before dumping it. Buffering in memory can be a problem if you are dumping large tables. To dump tables row by row, use the --quick option (or --opt , which enables --quick ).

How do I dump all MySQL databases?

To backup multiple MySQL databases with one command you need to use the --database option followed by the list of databases you want to backup. Each database name must be separated by space. The command above will create a dump file containing both databases.


1 Answers

The user has to be specified in the command and not in the file with the u parameter.

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

like image 53
Anshul Goyal Avatar answered Sep 21 '22 11:09

Anshul Goyal