Backup and Restore MySQL Databases

June 2, 2009 by  
Filed under Tips & Tricks

If you are using WordPress or other CMS for your website, it is important to do a regular backup of your website database. Because you don’t knows when disaster strike (hard disk failure, site been hacked, corrupted database, etc). At that time you will realize how important to backup your database.  Doing a MySQL database backup is quite easy. Just type a few command line and you have you backup that can be restore at any time.

Assume that you have root to your server. Initiate an SSH connection to your server and type the following command to backup your MySQL database.

mysqldump –u username –p databasename > backup.sql


Notes:

username – the username that has a privileges on the database
databasename – the name of database that you would like to backup
backup.sql – the backup file name

Once the database is backup you can restore it with the following command.

mysql –u username -p databasename < backup.sql