Skip to content

Instantly share code, notes, and snippets.

@mdauphin
Created November 30, 2015 10:09
Show Gist options
  • Save mdauphin/98f15f71d1788915ed49 to your computer and use it in GitHub Desktop.
Save mdauphin/98f15f71d1788915ed49 to your computer and use it in GitHub Desktop.
Extract table from MySQL dump gz compressed file
import sys
import gzip
'''
Extract table from MySQL dump file
use like this:
python extract_table.py filename.gz table_name > extract.txt
'''
with gzip.open(sys.argv[1],'rb') as f:
bIn = False
for line in f:
line = line.strip()
#LOCK TABLES `table_name` WRITE;
if line.startswith("LOCK TABLES"):
None
if line == "LOCK TABLES `%s` WRITE;" % sys.argv[2]:
bIn = True
elif line == "UNLOCK TABLES;":
bIn = False
elif bIn:
print line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment