Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make mysqldump skip the inserts for specific table?

Tags:

mysqldump

I'm regularly running mysqldump against a Drupal database and man, those cache tables can get huge. Considering that the first thing I do after reloading the data is clear the cache, I'd love it if I could just skip dumping all those rows altogether. I don't want to skip the table creation (with --ignore-tables), I just want to skip all those rows of cached data.

Is it possible to tell mysqldump to dump the CREATE TABLE statement skip the INSERT statements for a specific set of tables?

like image 270
abeger Avatar asked Jun 21 '12 15:06

abeger


2 Answers

There is a --no-data option that does this, but it affects all tables AFAIK. So, you'll have to run mysqldump twice.

# Dump all but your_special_tbl
mysqldump --ignore-table=db_name.your_special_tbl db_name > dump.sql

# Dump your_special_tbl without INSERT statements.
mysqldump --no-data db_name your_special_tbl >> dump.sql
like image 61
aioobe Avatar answered Sep 27 '22 19:09

aioobe


You have to call mysqldump twice.

The mysql-stripped-dump script does exactly this.

like image 23
Alex Avatar answered Sep 27 '22 18:09

Alex