Welcome to WebmasterWorld Guest from 50.17.114.227

Forum Moderators: open

Message Too Old, No Replies

Cron job to backup mysql database

what I do wrong?

     
10:01 am on Mar 10, 2007 (gmt 0)

New User

5+ Year Member

joined:Dec 21, 2006
posts:28
votes: 0


Hello,

I use this cron job to backup my database but it doesn't work:

mysqldump -u DBUSER DBNAME -p DBPASSWORD > databasefile.sql

can you tell me what is wrong?
thank you!

12:28 pm on Mar 10, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 23, 2003
posts:76
votes: 0


Try taking out the space after -p and -u so:

-uusername -ppassword

12:36 pm on Mar 10, 2007 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


but it doesn't work:

...

can you tell me what is wrong?

in general it's always a good thing to describe your results...

7:29 pm on Mar 10, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 27, 2001
posts:2547
votes: 0


The dbname should come last:

mysqldump -u DBUSER -p DBPASSWORD DBNAME > databasefile.sql

Also, that's not a fully formed crontab line, a full one might look like:


10 0 * * * cd /home/me/backups; /usr/bin/mysqldump --opt -u DBUSER -p DBPASS DBNAME > databasefile.sql

The --opt command is good for backing up databases, from the man file for crontab: "--opt Same as --add-drop-table --add-locks --all --extended-insert --quick --lock-tables".

10:32 am on Mar 12, 2007 (gmt 0)

New User

5+ Year Member

joined:Dec 21, 2006
posts: 28
votes: 0


thank you guys,

here is the message i get:

=======================================
Enter password: mysqldump: Got error: 1045: Access denied for user 'USER'@'localhost' (using password: NO) when trying to connect
=======================================

2:49 pm on Mar 13, 2007 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


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

you should enter as suggested by physics:

10 0 * * * cd /home/me/backups; /usr/bin/mysqldump --opt -u DBUSER -pDBPASS DBNAME > databasefile.sql

include the -p option and replace "DBPASS" with an actual password, since cron couldn't be bothered to provide one for you.
NO SPACE between "-p" and the password.
also make sure you replace "DBUSER" with a user that actually matches the provided password.