Repair and optimize MySQL databases

Mar 20, 2022 · 1 min read · Post a comment

In some of the previous posts, I’ve explained how to check if the MySQL tables are corrupted. So this topic will shed some light on how to auto-repair and optimize all MySQL databases and get rid of the corrupted tables.


  • MySQL
  • MariaDB
  • sudo privileges

Repair and Optimize MySQL databases

Step 1. To auto-repair all MySQL databases, run:

sudo mysqlcheck --check --auto-repair --all-databases

Step 2. Once the repair is done, optimize the databases.

sudo mysqlcheck --optimize --all-databases

Step 3. Restart the MySQL service.

sudo systemctl restart mysql


sudo systemctl restart mysqld


Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.