Thursday, September 24, 2009

MySQL Database backup (mysqldump) from command line

As the database grows in size the convenient GUI tools became too slow, at some point it is easier to log in to the database server and do it from the command line...

mysqldump --user MY_USER_NAME -p DB_NAME> /var/www/UNIQUE_NAME_AND_DATE.sql
Enter password: MY_PASSWORD

#compress, you can also use gzip
tar cvzf UNIQUE_NAME_AND_DATE.sql.tar UNIQUE_NAME_AND_DATE.sql

# delete sql
rm /var/www/UNIQUE_NAME_AND_DATE.sql

#download:
http://www.DOMAIN_NAME.com/UNIQUE_NAME_AND_DATE.sql.tar

# after transfer delete
rm /var/www/UNIQUE_NAME_AND_DATE.sql.tar