User

Repair and Optimize Tables

When and how to run REPAIR TABLE and OPTIMIZE TABLE on your MariaDB databases.

Last updated 1775606400

Go to Hosting Mode → Databases → [database] → Repair / Optimize.

Select one or more tables from the list and choose the operation to run.

REPAIR TABLE

REPAIR TABLE attempts to fix a corrupt table by rebuilding its index and recovering readable rows.

When to use it: A table becomes corrupt if the server crashes mid-write or disk I/O fails at the wrong moment. Symptoms include queries returning errors like Table './dbname/tablename' is marked as crashed and should be repaired.

[!IMPORTANT] REPAIR TABLE only works on MyISAM tables. Running it on an InnoDB table has no effect — InnoDB handles corruption differently using its own crash recovery and redo log. If an InnoDB table is corrupt, restore from a backup.

Most modern WordPress installations and PHP applications use InnoDB by default. Check the table engine in phpMyAdmin under the table's Structure tab if you are unsure.

OPTIMIZE TABLE

OPTIMIZE TABLE reclaims unused disk space and defragments the table's data file.

When to use it: After a large number of DELETE or UPDATE operations, MariaDB leaves gaps in the table's data file (the space freed by deleted rows is not immediately returned). Over time this can waste disk space and slow range scans.

Common situations where OPTIMIZE helps:

  • After deleting a large batch of old records (log tables, session tables, old orders).
  • After a major migration that involved many deletes and re-inserts.
  • If a table's "Data_free" value in phpMyAdmin is significantly large.

[!NOTE] OPTIMIZE TABLE on a large InnoDB table rebuilds the table in-place and locks it for writes during the operation. Run it during low-traffic periods on active production tables.

Running from SSH

You can also run these directly over SSH:

mysql -u username_dbuser -p username_dbname -e "REPAIR TABLE tablename;"
mysql -u username_dbuser -p username_dbname -e "OPTIMIZE TABLE tablename;"

Or from within the mysql shell:

USE username_dbname;
REPAIR TABLE tablename;
OPTIMIZE TABLE tablename;