This came up recently and I was happy to find a nice command to perform the task. This will run through every table in every database on a MySQL server and auto-repair and optimize them.

Depending on the size and number of databases this may take a while to complete:

mysqlcheck -u root -p -Aro

-A = Check all databases
-r = Repair databases
-o = Optimize databases

So if you only want to run the repair, take out the “o” argument and if you only want to optimize, take out the “r” argument.

Leave a Reply