Extract Single Table From mysqldump File

// August 4th, 2010 // Code, Featured

redeyedcoder

I wanted to restore a mysql table from a mysqldump file to another server, but I wanted to extract the information about this table only. One of the ways this can be accomplished is by using awk. This is the command I ran:

you@yourcomputer:$ awk '/Table structure for table .tablename./,/*!40000 ALTER TABLE .tablename. ENABLE KEYS/{print}' mysqldumpfile.sql > extracted_table.sql



The above command searches through the dump file, and as soon as it matches a line containing the first search string (denoted by the first set of slashes), it prints that line and every subsequent line until it encounters a line containing the second search string (denoted by the second set of slashes). FYI, the periods surrounding the table names above are wildcard characters.


These steps were found on this website, all credit goes to Jared. These steps worked best for me so I posted them here so it’d be easier for me to find it in the future whenever I needed them. There are other ways of accomplishing the same task, which can also be found there as well.


I hope this step by step tutorial has helped you some. Thank you for stopping by and please share with others, after all, code should be free.foscode.com | because code should be free

Share this post with:
  • Twitter
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • StumbleUpon
  • Yahoo! Buzz
  • Slashdot
  • Current
  • email
  • Tumblr

Leave a Reply