Created
November 30, 2015 10:09
-
-
Save mdauphin/98f15f71d1788915ed49 to your computer and use it in GitHub Desktop.
Extract table from MySQL dump gz compressed file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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