MySQL OPTIMIZE all tables?

Alan Storm picture Alan Storm · Mar 29, 2011 · Viewed 351.2k times · Source

MySQL has an OPTIMIZE TABLE command which can be used to reclaim unused space in a MySQL install. Is there a way (built-in command or common stored procedure) to run this optimization for every table in the database and/or server install, or is this something you'd have to script up yourself?

Answer

Ike Walker picture Ike Walker · Mar 29, 2011

You can use mysqlcheck to do this at the command line.

One database:

mysqlcheck -o <db_schema_name>

All databases:

mysqlcheck -o --all-databases