MySQL – Restore a single table from a mysqldump file.

A frequent task when working with MySQL is to restore a single table from a backup. This is typically an exercise where the admin must restore a full database to another MySQL instance and then export only the table in question. This is a great way to do it most of the time.

Another option is to use sed to extract only the single table from the mysqldump file and restore that to the running instance.

sed -n -e '/DROP TABLE.*`table_name`/,/UNLOCK TABLES/p' $dump_file > table_name.sql

This command will extract only the table_name table and allow restoration to the running instance.

I would also backup the table to be restored, just in case, and then restore it and verify.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *