Repair or optimize: which one the table needs
Run CHECK TABLE first. OPTIMIZE TABLE rebuilds a table and reclaims space, REPAIR TABLE only works on MyISAM and ARCHIVE, and ANALYZE TABLE just refreshes index statistics. In phpMyAdmin, select the database, tick the tables, then pick Check or Optimize from the With selected menu.
| Command | What it does | Runs on |
|---|---|---|
| CHECK TABLE | Reads the table and reports errors without changing it | InnoDB, MyISAM, ARCHIVE |
| REPAIR TABLE | Rebuilds a damaged index or data file | MyISAM, ARCHIVE, CSV; refused by InnoDB |
| OPTIMIZE TABLE | Rebuilds the table and returns free space to the disk | InnoDB (as ALTER TABLE FORCE), MyISAM, ARCHIVE |
| ANALYZE TABLE | Updates index statistics for the query planner | InnoDB, MyISAM |
A slow dashboard is not corruption. If pages load slowly but the data reads correctly, optimize or add an index; repair changes nothing on a table that already passes the check.
Back up the database before either command
Both commands rewrite files on disk. Take a dump first, then read the size before you trust it.
mysqldump -u user -p --single-
--single-
Confirm the file before running anything: gzip -l dbname-2026- should show a size close to the database size, and zcat dbname-2026- should show CREATE TABLE lines. Copy it off the server, because a dump stored in the same account leaves with the account.
Repair tables in phpMyAdmin
phpMyAdmin is the shortest route when the database is small and SSH is not open.
- Log in to cPanel, then phpMyAdmin. The client area where you pay invoices is a separate login.
- Click the database name in the left column, then tick the tables. Use Select all when the whole database is suspect.
- From the With selected menu at the bottom, choose Check table and read the Msg_text column.
- If a MyISAM table reports an error, repeat the selection with Repair table.
- When the repair returns OK, run Optimize table on the same selection to reclaim the space.
- Reload the site. It is fixed when the page loads and a second Check table returns OK for every row.
phpMyAdmin clears the selection after each action, so re-tick the tables every time. A repair on a 1 GB MyISAM table can run for minutes; leave the tab open until the result table appears.
Run mysqlcheck from the command line
mysqlcheck takes one flag per job and runs over SSH or the terminal in the hosting panel.
mysqlcheck -c dbname -u user -pchecks every table in one database.mysqlcheck -r dbname -u user -prepairs the tables that failed the check.mysqlcheck -o dbname -u user -poptimizes, which is the rebuild.mysqlcheck -a dbname -u user -prefreshes statistics after a large import.mysqlcheck -o --all-databases -u root -pruns the pass over every database on the server.
Add --auto-repair to a check run to fix what it finds in the same pass. Each table is locked while it is processed, so a server-wide run belongs in a maintenance window, not at noon.
On WordPress, the wrapper reads the credentials from wp-config.php: wp db check and wp db optimize call the same tools without the flags.
InnoDB versus MyISAM after a crash
InnoDB has been the default engine since MySQL 5.5. It keeps one .ibd file per table, recovers from its redo log after a crash, and refuses REPAIR TABLE because it either recovers itself or needs a restore. MyISAM has no crash recovery, so a power cut can leave a table marked as crashed, and REPAIR TABLE can rebuild it by dropping rows it cannot read.
| Behaviour | InnoDB | MyISAM |
|---|---|---|
| After a crash | Recovers from the redo log on start | Needs a check and often a repair |
| REPAIR TABLE | Refused | Accepted, may lose rows |
| OPTIMIZE TABLE | Online rebuild, brief exclusive lock | Locks the table for the whole job |
| Files on disk | One .ibd per table | .MYD, .MYI and .frm per table |
| Convert with | ALTER TABLE wp_posts ENGINE= | ALTER TABLE wp_posts ENGINE=MyISAM; |
Converting to InnoDB is the durable fix for a table that keeps crashing. Run the ALTER in a quiet hour: it rebuilds the table and needs free disk space roughly the size of the table.
How to tell a table is really corrupted
These messages mean damage. A slow admin page, a timeout or a failed plugin does not.
- "Table is marked as crashed and should be repaired" — a MyISAM table; run repair once.
- Error 145 or 1194 — table marked as crashed, or corrupt.
- "Incorrect key file for table" — index damage, usually MyISAM.
- "Database page corruption on disk or a failed file read" — InnoDB, restore.
- CHECK TABLE returns Error or Corrupt in the Msg_text column.
If CHECK returns OK and the site still fails, the fault may be a full disk, a dropped connection or a missing table. Compare SHOW TABLES; with the table prefix in wp-config.php before you repair anything.
When to restore instead of repair
Restore when a second repair fails, when the message names an InnoDB page or checksum, or when the table opens but rows are missing. A restore replaces the table with the last dump, so orders and posts written after that dump disappear.
- Copy the damaged table out:
mysqldump -u user -p dbname wp_posts > wp_posts-.broken.sql - Rename the live table so the site fails cleanly instead of half-reading it:
RENAME TABLE wp_posts TO wp_posts_old;. - Import the dump with
mysql -u user -p dbname < dbname-2026-, or10-29.sql wp db import dbname-2026-.10-29.sql - Compare row counts with the old table, then drop the copy once the site has run a full day.
A single-table restore is possible: pull that table's CREATE and INSERT lines from the dump, import only those, and leave the rest of the database untouched.
Keeping tables small on WebJi hosting
Optimize returns space after deletes but does not stop the growth. On WordPress, revisions, expired transients and autoloaded options are the usual weight in wp_posts and wp_options; the wp_options cleanup guide covers that cleanup, which is a different job from repair.
Our Linux hosting plans include phpMyAdmin, SSH and the MySQL users these commands need. If the check output is not clear, email support@webji.
Frequently Asked Questions
Should I repair or optimize a MySQL table?
Run CHECK TABLE first. Repair is for a table that fails the check and uses MyISAM or ARCHIVE. Optimize is for a healthy table that has lost space to deletes or replaced rows, and it rebuilds the table rather than fixing errors. Analyze only refreshes index statistics.
How do I repair a table in phpMyAdmin?
Open phpMyAdmin, click the database in the left column, tick the tables, then choose Check table from the With selected menu. If the output reports an error on a MyISAM table, repeat with Repair table. Read the message column: a green OK is a pass, and anything else needs the full text copied out.
Why does REPAIR TABLE say the storage engine does not support repair?
InnoDB does not accept REPAIR TABLE. The statement only repairs MyISAM, ARCHIVE and a few CSV tables, so the server refuses instead of rebuilding. For an InnoDB table, dump what still reads, then restore, or run OPTIMIZE TABLE if the table is intact but bloated.
What is the mysqlcheck command to optimize all databases?
mysqlcheck -o --all-databases -u root -p optimizes every table in every database. Swap -o for -r to repair, -c to check, or -a to analyze. Add --auto-repair to fix what the check finds in the same pass. The account needs SELECT and INSERT privileges on each table.
Does OPTIMIZE TABLE lock the table?
On InnoDB it runs online and takes an exclusive lock only briefly while the rebuild starts and commits. On MyISAM the table is locked for the whole operation, so a large table keeps readers waiting. Run it in a low-traffic window and expect a long job on tables over a few hundred MB.
When should I restore the database instead of repairing it?
Restore when a second repair attempt fails, when the error names an InnoDB page or checksum, or when the table opens but rows are missing. A restore replaces the table with the last good dump, so any order placed after that dump is lost. Copy the damaged table out first.

