Skip to content

Instantly share code, notes, and snippets.

@jystewart
Created May 21, 2011 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jystewart/984587 to your computer and use it in GitHub Desktop.
Save jystewart/984587 to your computer and use it in GitHub Desktop.
Query to generate OPTIMIZE TABLE statements for all fragmented tables
SELECT CONCAT('OPTIMIZE TABLE ', TABLE_SCHEMA,'.',TABLE_NAME, ';'), Data_free from information_schema.TABLES where TABLE_SCHEMA NOT IN ('information_schema','mysql') and Data_free > 0 AND ENGINE NOT IN ('INNODB', 'MEMORY');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment