extracting a specific table from a mysqldump file

There was some discussion on #lopsa about doing backups of mysql using mysqldump and having to deal with extracting tables from large dump files. This is what I came up with. It’s worked well enough for extracting full tables from a RHEL4U1 mysql dump.


#!/usr/bin/perl -wn
#
# extract a specific table from a mysql4.X dump file.
#
# gzip -c -d .gz | extract_mysql_table #
use warnings;
BEGIN { $table = shift || die "No table specifiedn"; }
#print if /^create table `?$tableb/io .. /^create table `?(?!$table)b/io;
print if m|^-- Table structure for table `$tableb|io ..
m|/*!40000 ALTER TABLE `$table` ENABLE KEYS */;|io ;

I’ve used this for extracting small and large tables on dumps that were in excess of 12-15GB.