Repairing and Optimizing all MySQL and MariaDB Databases on the Server

Server Maintenance | Updated 2026

Regularly repairing and optimizing MySQL/MariaDB tables reclaims unused space, fixes corrupted indexes, and improves query performance. Here is how to do it at both the account and server level.

01. Server-Wide Optimization (Root)

# Check, repair, and optimize all databases
mysqlcheck -u root -p --all-databases --check --optimize --auto-repair

# Or separately:
mysqlcheck -u root -p --all-databases --repair
mysqlcheck -u root -p --all-databases --optimize

02. Automate With Cron

# Weekly optimization - add to root crontab
0 3 * * 0 mysqlcheck -u root --all-databases --optimize --auto-repair >/dev/null 2>&1
InnoDB Note

For InnoDB tables, OPTIMIZE TABLE actually performs a table rebuild (ALTER TABLE ... ENGINE=InnoDB). This can temporarily lock the table and use significant disk space for large tables. Run during low-traffic periods. For ibdata1 bloat, see Shrink ibdata1.

For backups before maintenance: Backup MySQL.

Database Issues?

Open a Support Ticket

Quick Recap

  1. phpMyAdmin: Check all > Optimize table
  2. SSH: mysqlcheck --optimize --auto-repair
  3. Server-wide: --all-databases flag (root only)
  4. Automate weekly via cron
  5. InnoDB optimize rebuilds tables - Run off-peak

Database maintenance · Last updated March 2026 · Browse all Server Maintenance articles

  • 147 Users Found This Useful

Was this answer helpful?

Related Articles

Failed to start tailwatchd - Unit tailwatchd service entered failed state

Server Maintenance | Updated 2026 The error Failed to start tailwatchd - Unit...

ModSecurity: collection_store: Failed to access DBM file /var/cpanel/secdatadir/ip: Permission denied

Server Maintenance | Updated 2026 The error collection_store: Failed to access DBM file...

Clear cPanel Eximstats DB and Repairing the Eximstats DB

Server Maintenance | Updated 2026 The Eximstats database in cPanel tracks email delivery...

VPS Time Not Correct with Time Server

Server Maintenance | Updated March 2026 When a VPS or dedicated server's system clock drifts...

Whitelisting Multiple IPs with ModSecurity

Server Maintenance | Updated March 2026 ModSecurity (our web application firewall)...



Save 30% on web hosting - Use coupon code Hosting30