Skip to content

Optimize and repair MySQL tables

Over time, tables with lots of deletes/updates accumulate wasted space and can occasionally get corrupted (often after a crash or a disk-full event). Two simple maintenance commands keep MySQL/MariaDB healthy.

Reclaim space with OPTIMIZE

After deleting a lot of rows, the disk space isn’t automatically returned. OPTIMIZE rebuilds the table and reclaims it:

OPTIMIZE TABLE wp_options;
OPTIMIZE TABLE orders, order_items; -- several at once

In phpMyAdmin you can select tables and choose Optimize table from the dropdown — no SQL needed.

Check and repair

If you see errors like “table is marked as crashed”:

CHECK TABLE sessions; -- diagnose
REPAIR TABLE sessions; -- fix (MyISAM/Aria)

phpMyAdmin has Check table and Repair table in the same dropdown.

InnoDB (the modern default) doesn’t use REPAIR TABLE. If an InnoDB table is corrupt, the fix is to restore from a backup — which is exactly why you keep them.

When to run OPTIMIZE

  • After bulk deletes (clearing logs, spam, old sessions).
  • On a heavily-churned table (e.g. WordPress wp_options, a sessions table).
  • Not constantly — it locks the table while it runs; schedule it for a quiet time.

Prevent corruption in the first place

  • Keep enough free disk — a full disk mid-write is a classic corruption cause. → Disk & memory
  • Keep backups so recovery is a restore, not a gamble.

Running OrbixPanel? phpMyAdmin’s one-click Optimize/Repair is built in. OrbixPanel.com → — the free, self-hosted, AI-powered hosting control panel.