DBAtlas · Database operations atlas

OPTIMIZE a table

MySQLStorage

Command

OPTIMIZE TABLE customer;

What it does

Rebuilds the table to remove fragmentation, reclaim unused space and update index statistics.

When to use it

To reclaim space in an InnoDB table bloated by many DELETEs/UPDATEs.

Caution

On InnoDB, OPTIMIZE actually runs as an online ALTER that rebuilds the table, but it still needs I/O and temporary disk space; large tables require free disk equal to the table size. Run it during low traffic to reduce locking.

Open in DBAtlas →

Related