+63 920 196 8608
Not a customer yet? Sign up now!

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:

  1. Log in to WHM as root.

  2. Navigate to:
    SQL Services → Repair a MySQL® Database

  3. 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

mysqlcheck -c --all-databases -u root -p

Repair All Databases

mysqlcheck -r --all-databases -u root -p

Optimize All Databases

mysqlcheck -o --all-databases -u root -p

Full Check + Repair + Optimize

mysqlcheck -Acr --auto-repair -u root -p

Automating with Cron

To keep databases healthy, you can schedule automatic checks and repairs.

Edit root’s cron jobs:

crontab -e

Add a weekly job (runs every Sunday at 3 AM):

0 3 * * 0 mysqlcheck -Acr --auto-repair >/dev/null 2>&1

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:

[client] user=root password=YourRootPassword

Secure it:

chmod 600 ~/.my.cnf

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: ,