Mysql – How to restore a specific table from a big thesqldump file

MySQLmysqldumprestore

From a very big backup file (created by mysqldump) I need to bring back only one (or a few) specific table(s), without loading all tables.

Are there any fast alternatives?

Best Answer

You could achieve that by two steps :

Step 1 : Locate position of your table(or tables) and it (them) in a file :

 grep -n "Table structure" your_dump_file > list_tables_NUM.TXT

This will create a list of all tables ranked by position, example :

cat list_tables_NUM.TXT
...
41743:-- Table structure for table `table_X`
41770:-- Table structure for table `table_Y`    
42780:-- Table structure for table `table_Z`
...

Based-on that result you will create a secondary file containing that specific table, let's assume that you need to restore only table_X and table_Y:

Step 2 : Extract from position 41743 to 42780 :

sed -n '41743,42780 p' your_dump_file > dump_table_XY.sql

At the final, you may find your tables (structure+data) in the dump_table_XY.sql

Tested for MySQL/Mariadb in Centos7