HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Can mysql restore a single table from a large mysqldump?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
canrestoremysqldumpmysqlsinglelargefromtable

Problem

What is the best way to restore a single table from a large (~5GB) database mysqldump file?

update:
I have found solutions (posted below) using command line tools to parse the table, but is there a way to do this with mysqlimport?

Solution

I have found two solutions, one using

grep -n "Table Structure" mydump.sql
# identify the first and last line numbers (n1 and n2) of desired table
sed -n n1,n2p mydump.sql > mytable.sql # (e.g. sed -n 48,112p)


and one using awk

awk '/Table Structure for table .table1./, /Table structure for table .cultivars./{print}' mydump.sql > mytable.sql

Code Snippets

grep -n "Table Structure" mydump.sql
# identify the first and last line numbers (n1 and n2) of desired table
sed -n n1,n2p mydump.sql > mytable.sql # (e.g. sed -n 48,112p)
awk '/Table Structure for table .table1./, /Table structure for table .cultivars./{print}' mydump.sql > mytable.sql

Context

StackExchange Database Administrators Q#14716, answer score: 10

Revisions (0)

No revisions yet.