Monday, 22 November 2010

Restoring your MySQL Database

Create an appropriately named database on the target machine
Load the file using the mysql command:
# mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]

Have a look how you can restore your tut_backup.sql file to the Tutorials database.
# mysql -u root -p Tutorials < tut_backup.sql

To restore compressed backup files you can do the following:
# gunzip < [backupfile.sql.gz] | mysql -u [uname] -p[pass] [dbname]

If you need to restore a database that already exists, you'll need to use mysqlimport command. The syntax for mysqlimport is as follows:
# mysqlimport -u [uname] -p[pass] [dbname] [backupfile.sql]

No comments:

Post a Comment