Slowcoder
Slowcoder

Reputation: 2120

Ignoring the data for specific tables while restoring mysql database from dump

I have a huge dump file with around 200 tables and millions of records for some of those tables. I know it is possible to ignore specific tables when I do mysqldump .

Is it possible to ignore some tables or ignore just the insert queries for those tables while "restoring" the database from a dump?

Thanks in advance.

Upvotes: 2

Views: 2225

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 562741

There's no way to do this with the mysql client. The dump file is basically a big collection of CREATE TABLE and INSERT statements (and some others), and the mysql client doesn't have any way of executing part of such an SQL script.

However, I have done it when necessary by being creative with sed. For example, if I want to exclude the creation and data for table "do_not_want", I could do this:

cat mydumpfile.sql |
sed -e '/^-- Table structure for table .do_not_want./,/^UNLOCK TABLES;/d' |
mysql

This assumes that the patterns we're using for the boundaries don't occur in the data itself.

Upvotes: 1

Related Questions