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

Remove redundant disable/enable key statements from mysqldump

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

Problem

A standard mysqldump will create a table, disable keys, insert the data, and re-enable keys. There are reasons for this. However, when a table is empty, the keys are still disabled and re-enabled.

LOCK TABLES `Brands` WRITE;
/*!40000 ALTER TABLE `Brands` DISABLE KEYS */;
/*!40000 ALTER TABLE `Brands` ENABLE KEYS */;
UNLOCK TABLES;


This little block of code, repeated multiple times, is surely slowing down inserts for no good reason. Is there any way to remove it, or to prevent its creation in the first place? I imagine that it is no big deal, but I’m still curious.

Solution

Don't worry, DISABLE KEYS and ENABLE KEYS are artifacts from mysqldump of bygone days

These commands, DISABLE KEYS and ENABLE KEYS have absolutely no effect on InnoDB Tables (they were not implemented for the InnoDB Storage Engine). They were designed specifically for MyISAM tables. You will just get warnings.

I have written about this many times as far back as May 2011

See MySQL Documentation on this

You can create dumps without them with

mysqldump ... | grep -v "ABLE KEYS" > dumpfile.sql

Code Snippets

mysqldump ... | grep -v "ABLE KEYS" > dumpfile.sql

Context

StackExchange Database Administrators Q#328298, answer score: 3

Revisions (0)

No revisions yet.