Thursday, May 8, 2014

Restore a Single Database from a Full MySQL Database Dump file

You have a full backup of all databases on a MySQL instance and you want to restore only a single Database from that full backup (rather than all the DBs).


Here’s how (use “cat” instead of “zcat” if your full backup is not compressed with gzip:


zcat path_to_full_mysqldump_Backup | sed -n -e ‘/Current Database:.*`characters/,/Current Database:/p’ | mysql -h ip_of_server_you_want_to_restore_to -P port_of_server_instance_you_want_to_restore_to –protocol=tcp -u mysql_username_on_server_you_want_to_restore_to -p –database=name_of_database_you_want_to_restore_to


If you want to test the output before running it remove the “mysql….” at the end of the line and dump it to a text file like this:


zcat path_to_full_mysqldump_Backup | sed -n -e ‘/Current Database:.*`characters/,/Current Database:/p’ > testingout.sql


Then look at the first 20 lines or so to ensure there are statements that create the expected database, and then look at the last line to ensure there are no more statements regarding creation of a different DB (you will likely see a big insert statement for the last line).





No comments:

Post a Comment