Restore Your MySQL Database from a Backup File

We’ve already shown you how to create a backup of your MySQL server from the command line, but it’s very important to know how to restore that data just in case you should need to recover from a failure. You should also make a point of testing out your recovery process on another box, just to make sure it’s working properly.

The syntax to restore your database from the command line:

mysql -h hostname -u username -pthepassword databasename < dumpfile.sql

Here’s an example:

mysql -h localhost -u root -p72aDufi8 db01 < thedumpfile.sql

Keep in mind that this will pretty much wipe your current database, so proceed with caution.

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.