How to Optimize and Repair Databases in WHM/cPanel
If you’re running a cPanel or WHM server, database issues can occasionally slow down your websites or cause unexpected errors. MySQL/MariaDB provides a built-in tool called mysqlcheck
that allows you to check, repair, and optimize databases with just a few commands.
In this guide, we’ll walk you through optimizing and repairing all databases in WHM/cPanel — both via the WHM interface and command line.
Why Optimize and Repair Databases?
Over time, MySQL tables can become fragmented or corrupted due to:
-
Heavy read/write operations
-
Unexpected crashes or server reboots
-
Improper shutdowns
-
Large or busy WordPress/WooCommerce sites
Running regular optimization and repair helps:
✅ Improve performance
✅ Fix common table errors
✅ Reduce unnecessary disk usage
Method 1: Repair a Database via WHM
If you have WHM access:
-
Log in to WHM as root.
-
Navigate to:
SQL Services → Repair a MySQL® Database -
Select the database you want to repair and click Repair.
Note: WHM allows repairing one database at a time. To optimize and repair all databases, you’ll need SSH access.
Method 2: Optimize & Repair All Databases via Command Line
If you have root SSH access, you can use mysqlcheck
to optimize and repair every database at once.
Check All Databases
Repair All Databases
Optimize All Databases
Full Check + Repair + Optimize
Automating with Cron
To keep databases healthy, you can schedule automatic checks and repairs.
Edit root’s cron jobs:
Add a weekly job (runs every Sunday at 3 AM):
Pro Tip: Avoid Storing Passwords in Scripts
Instead of adding your MySQL root password directly in commands or cron jobs, create a hidden .my.cnf
file:
Secure it:
Now you can run mysqlcheck
without typing the password each time.
Conclusion
Regularly optimizing and repairing databases is essential for keeping your WHM/cPanel server running smoothly. Whether you use the WHM interface for a quick repair or automate it with mysqlcheck
in SSH, maintaining database health will improve performance and reduce errors.
If you manage busy WordPress or eCommerce sites, consider scheduling regular optimizations to keep everything fast and reliable.
Tags: database, mysql