The following snippet can be used to extract a table from a MySQL backup file created with mysqldump. It is ideal when working with massive databases, and is something I use once in a while myself.

zcat backupfilename.sql.gz | sed -n -e '/CREATE TABLE.*`tableToRecover`/,/CREATE TABLE/p' > tableToRecover.sql

If you wish to extact a table, and re-gzip it, the following will be more suitable:

zcat backupfilename.sql.gz | sed -n -e '/CREATE TABLE.*`tableToRecover`/,/CREATE TABLE/p' | gzip -9 > tableToRecover.sql.gz

However, I recommend using pigz over MySQL as it will make use of multiple cores on your machine.

Show CommentsClose Comments

Leave a comment