MySQL – Repair and optimize tables

Repair and optimize all tables

After upgrading the MySQL server there are times when weird bugs would be seen with a possibility of no errors thrown. It is therefore recommended that you repair and optimize databases and tables immediately after the upgrade.

To do so you can run the following MySQL queries for each table you want to repair and optimize:

# For each table
REPAIR TABLE table_name;
OPTIMIZE TABLE table_name;

Now this can be an enormous task when you have many databases and tables but there is an alternative using the mysqlcheck command

$ mysqlcheck -u root -p –auto-repair –optimize –all-databases

Once you have entered the password this utility will repair and optimize all tables in all databases.

 

Leave a Reply