Wednesday, October 7, 2009

Backup of mysql database

I usually need to backup my (mysql) database for transferring it from one pc to another or to transfer it to my partner working on the same project or to take a back up of the production database of my website. We could do it simply using a single command from the command prompt:

mysqldump [options] db_name [tables]

You could use this command as:
mysqldump -u root project_production > backup.sql
or
mysqldump project_production > backup.sql
(depending on the permissions)

This will generate a file backup.sql in your current directory which could be used to regenerate the database any time in future on the same or different pc.

Importing the data from the backup file is much more simpler. Just type on the command prompt:
mysql -u root project_development < backup.sql

This will copy all the data from the backup file to another database named project_development.

For more information, visit this site.