How to Repair and Optimize MySQL Databases in cPanel

64 views
Short answer: Navigate to cPanel MySQL Databases, select your database from the 'Modify Databases' dropdown, and click 'Repair Database' followed by 'Optimize Database' to rebuild indices.

Fix corrupted database tables, reclaim unused disk space, and defragment indexes using cPanel MySQL tools and phpMyAdmin.

Before you start: Back up your site files and database and download the backup to your own computer. How to take a full backup

Quick reference

cPanel Native Tool cPanel > Databases > MySQL Databases > Modify Databases
Advanced Tool phpMyAdmin > Select Database > Check All > Repair table
Table Engines InnoDB & MyISAM

Steps

  1. Open MySQL Databases: In cPanel, navigate to Databases > MySQL Databases.
  2. Repair Database via cPanel:
    • Scroll down to the Modify Databases section.
    • In the Repair Database dropdown, select the target database.
    • Click Repair Database. cPanel runs an automated integrity check and displays status flags (OK) for all tables.
  3. Optimize Database (Reclaim Disk Space):
    • Under Optimize Database in the same section, select your database and click Optimize Database.
    • This removes overhead from deleted rows and defragments indices.
  4. Alternative - Repair in phpMyAdmin:
    • Open phpMyAdmin from cPanel.
    • Click your database name on the left sidebar.
    • Scroll to the bottom of the table list, check Check all.
    • In the With selected: dropdown, choose Repair table or Optimize table.

Repair & Optimize MySQL Tables via CLI

# Repair every database table with mysqlcheck
mysqlcheck -u DB_USER -p --auto-repair --optimize DB_NAME

# Or with WP-CLI for WordPress
wp db optimize --path=/home/USER/public_html

Troubleshooting and tips

  • InnoDB Table 'Doesn't exist in engine': If an InnoDB data dictionary becomes mismatched due to improper file deletion, standard repair scripts may report failure. In this case, restore the database from your most recent healthy backup.
  • Read-Only Lock during Optimization: On high-traffic production databases, optimizing very large tables can temporarily lock writes. Perform optimization during low-traffic hours.
Need more help? If you run into an error while following these steps, open a ticket with technical support and our team will look into it. Open a ticket
Was this article helpful?
No, I need more help
Didn't find your answer?
Under 3 minutes
Submit Support Ticket