OPTIMIZE TABLE
CautionRebuild/defragment tables
OPTIMIZE TABLE <table>;
Reclaims space after mass deletes; on InnoDB it's a rebuild — schedule it, it locks and takes time.
Examples
OPTIMIZE TABLE session_log;Rebuild a bloated table
Syntax
OPTIMIZE TABLE t;(MySQL)
Before you run it
Locks and load during the rebuild.
Related commands
- VACUUMVacuum (PostgreSQL)
- ANALYZE TABLERefresh optimizer stats
The same reference, with no signal at all
Every command on this site, held on your device. The app adds 632 more: 1,510 commands and 120 fix flows, searchable with no connection. Free to install, no ads (some content is a one-time purchase).
Get it free on the App Store