Thoughts that are my own.

Extracting Single Table From Mysql Dump File

Using awk, it is possible to extract a single table from a mysql dump file. You will need to know the name of the table you want AND the name of the table immediately after the table you want. I was able to find this info quicker than loading the whole dump file by going to mysql and looking at the table order and finding the table after the one I was looking for.

After getting the required information, apply some awk magic like such.

awk '/Table structure for table .firstTable./,/Table structure for table .secondTable./{print}' name_of_dump_file > output_file.sql

The awk statement above is printing all text from the location of the first match to the location of the second match. Matches are denoted by the text inside the forward slashes. In the above, search criteria one (starting point) is “Table structure for table .firstTable.” and search criteria two (stopping point) is “Table structure for table .secondTable.”. Make sure you replace “firstTable” and “secondTable” with the tables discussed earlier.

Check over your new output file and make sure it has the table you wanted and then you can import it using standard mysql commands.

Originally Posted April 2010