Database Backup with mysqldump
Thursday, 31 January 2008
Mysqldump is a simple client used to backup MySQL databases or to transfer databases into another servers. It stores SQL statements to create tables and to import them. The client can also be used to create formatted files and generate XML files.

Example:

%> mysqldump -u username -p dbname > backup.sql
%> mysqldump -u username --all-databases > backup_all.sql

If you have a linux box, type the following command to get a complete help of mysqldump.

%> mysqldump --help | less


Backup and Compress at One

Pipelining gzip together with mysqldump in the command line is a quick and easy way to backup and to compress:

%> mysqldump -u username -p dbname | gzip > backup.gz


Restore the Backup

Use the following command to import a backup into an empty mysql database:

%> mysql -u username -p dbname < backup.sql

Or, if you have your backup zipped, you can use gunzip to unzip it and then use mysql to import:

%> gunzip < backup.gz | mysql -u username -p dbname