If you find yourself in the unfortunate position of losing all your data from a dead hard drive or non-posting server you immediately realize…hey, I should have backed up my data! Well here are a few steps to backup specific databases within MySQL, or your entire database. I am assuming you have your database password and the ability to login to it.
There is a great tool called mysqldump that has:
mysqldump -u [username] -p [password] [databasename] > [backupfile.sql]
- [username] – this is your database username
- [password] – this is the password for your database
- [databasename] – the name of your database
- [backupfile.sql] – the file to which the backup should be written.
Lets say you have a WordPress database and you want to back that to a file. You simply enter the command:
$ mysqldump -u [uname] -p[pass] [dbname] | gzip -9 > [backupfile.sql.gz]
This will also compress your backup using gzip to save space on your harddrive. Voila!