Recover a single table from a mysqldump
I needed to recover the data, from a single table, from a mysqldump containing all the databases from an entire instance. A quick google yielded this result. This produced a nifty little sed one-liner…
sed -n -e '/CREATE TABLE.*your_table_name/,/CREATE TABLE/p' mysqldump_file.sql > your_table_name.sql
I also wanted to import the data into a different table. Again sed came to the rescue…
sed -i -e 's/your_table_name/new_table_name/g' new_table_name.sql
As always, you should never 100% trust anything you find on the Internet. I did a quick check for any DROP statements…
cat new_table_name.sql | grep DROP;
This showed my file contained an unexpected DROP TABLE statement. It might be an idea to quick visually scan the file. If it’s too big then inspecting each end of the file with head and tail would be a good idea. Quick, simple easy process to getting your data back!