mysql,

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.

Prerequisites

  • 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.
Debian-based:

sudo systemctl restart mysql

RHEL-based:

sudo systemctl restart mysqld

Conclusion

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