Restore single MySQL table from large DB dump

Here’s how to restore one or more tables from a full database archive. It assumes you used mysqldump to save the database and stored it in a gz file. First create the file

#!/usr/bin/perl -wn
BEGIN { $table = shift @ARGV }
print if /^create table $table\b/io .. /^create table (?!$table)\b/io;

Then do the following to restore the table:

zcat /path/ | extract-table Mytable> ~/Mytable.dump
mysql  mydatabase -e "drop table Mytable"
mysql mydatabase


Comments are closed.

%d bloggers like this: