snippetsqlModerate
How to restore a specific table from a big mysqldump file?
Viewed 0 times
filehowrestoremysqldumpbigspecificfromtable
Problem
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?
Are there any fast alternatives?
Solution
You could achieve that by two steps :
Step 1 : Locate position of your table(or tables) and it (them) in a file :
This will create a list of all tables ranked by position, example :
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 :
At the final, you may find your tables (structure+data) in the dump_table_XY.sql
Tested for MySQL/Mariadb in Centos7
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.TXTThis 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.sqlAt the final, you may find your tables (structure+data) in the dump_table_XY.sql
Tested for MySQL/Mariadb in Centos7
Code Snippets
grep -n "Table structure" your_dump_file > list_tables_NUM.TXTcat 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`
...sed -n '41743,42780 p' your_dump_file > dump_table_XY.sqlContext
StackExchange Database Administrators Q#281830, answer score: 10
Revisions (0)
No revisions yet.