MySQL – restore databases (command line – Linux)

Methods of restoring MySQL databases

To restore a MySQL database you can use one of the following methods after creating a new blank database

$ mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]
e.g.
$ mysql -u root -p WebDB < WebDB_backup.sql

To restore compressed backup file directly, you can do the following:

gunzip < [backupfile.sql.gz] | mysql -u [uname] -p[pass] [dbname]
e.g.
gunzip < [WebDB_backup.sql.gz] | mysql -u root -p WebDB

Leave a Reply