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

Create CXS Quarantine Directory

Server Maintenance | Updated 2026 ConfigServer eXploit Scanner (CXS) quarantines suspicious...

SpamAssassin Command Line Bayesian Learn Command cPanel

Server Maintenance | Updated 2026 SpamAssassin's Bayesian filter learns from your email to...

error: db3 error(-) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery

Server Maintenance | Updated 2026 The error db3 error(-30974) from dbenv->failchk:...

Disable cPanel Brute Force Command Line

Server Maintenance | Updated 2026 cPHulk is cPanel's built-in brute force protection. It...

How to convert InnoDB to MyISAM

Server Maintenance | Updated 2026 Converting tables between InnoDB and MyISAM storage engines...



Save 30% on web hosting - Use coupon code Hosting30