Repair and optimize all mysql tables from CLI
Archived post, originally published March 22, 2011. Kept for reference — commands and package names reflect the distributions of the time and may have changed.
Here’s how to check, repair and optimize all your mysql tables in all databases on a server…
mysqlcheck -u root -p - -auto-repair --check --optimize --all-databases
Note: you do not have to have root to do this, simply replace -u root with -u yourusername
That’s it..
(Remember if you are using a tool like phpmyadmin (http://www.phpmyadmin.com) you can always log in, browse to the table, select operations and choose “repair”, “check”, “analyse” or “optimize table”)