How to repair a corrupted MySQL table
A corrupted table has a specific fix, and it is different depending on whether the table is MyISAM or InnoDB.
A corrupted table announces itself clearly enough: WordPress shows a message about needing database repair, a query returns an error mentioning the table is marked as crashed, or phpMyAdmin refuses to open a table's contents. It is rare, but when it happens it is fixable, and the fix depends on which storage engine the table uses.
Confirm it is actually corruption
Before assuming the worst, check with CHECK TABLE, which inspects a table without changing anything:
CHECK TABLE table_name;
Run this from the SQL tab in phpMyAdmin, or from a MySQL client if you have one. The result column will say OK if the table is fine, or describe the specific problem if it is not. This matters because the same front-end symptom — a broken-looking page — has several other causes entirely unrelated to table corruption, and there is no point repairing a table that was never damaged.
MyISAM tables: REPAIR TABLE works directly
If the table uses the older MyISAM storage engine, MySQL's own repair command handles it:
REPAIR TABLE table_name;
In phpMyAdmin, the same action is available without typing SQL: open the database, tick the box next to the affected table, and choose Repair table from the "With selected" dropdown at the bottom of the table list.
REPAIR TABLE is generally safe and its purpose is recovery, not deletion, but severely damaged rows can occasionally be dropped rather than fixed. If the table is reachable and you can export it first — even a partial, error-riddled export — do that before repairing, so you have something to fall back on.
InnoDB tables: REPAIR TABLE does not do what you expect
This is the detail that catches people out. REPAIR TABLE only operates on the MyISAM, ARCHIVE and CSV storage engines. Run it against an InnoDB table — which is the default engine, and the one WordPress and most modern applications use — and MySQL does not perform a real repair. It typically reports that the storage engine does not support the operation, or performs a no-op that leaves the underlying corruption untouched.
Running REPAIR TABLE against an InnoDB table and seeing no error is not confirmation of a repair. Always follow up with CHECK TABLE afterwards and confirm it actually reports OK before you consider the problem solved.
InnoDB corruption is rarer than MyISAM corruption because the engine is designed to be crash-safe, but when it does happen the practical options are different:
- Restore from a backup. This is the most reliable fix, and it is why a working backup routine matters more than any repair command. See restoring a database backup.
- Dump and reload the table. If the table is still readable enough to export, exporting its data and reimporting it into a freshly created table rebuilds it from scratch, discarding whatever internal corruption existed in the old table's files.
- Server-level recovery. Genuinely severe InnoDB corruption — where the table cannot be read at all — sometimes needs the database server itself started in a special forced-recovery mode to extract what data it can. That is a server-side operation rather than something available from within phpMyAdmin, and it is the point at which contacting your host's support is the right next step rather than continuing to experiment on a live table.
After a successful repair
Run OPTIMIZE TABLE once the table checks out clean. A repair can leave a table larger and less efficient than it needs to be, and optimising reclaims that space and rebuilds index statistics:
OPTIMIZE TABLE table_name;
Our guide to optimising a MySQL database covers this in more detail, including when it is worth running proactively rather than only after a repair.
If WordPress is the one asking for a repair
WordPress has its own repair screen, reached by adding define('WP_ALLOW_REPAIR', true); to wp-config.php and visiting yourdomain.com/wp-admin/maint/repair.php. It runs the same underlying CHECK TABLE and REPAIR TABLE logic described above across every WordPress table in one pass, which is convenient, but the InnoDB limitation above still applies — it will not fix genuine InnoDB corruption any more than running the commands manually would. Remove the line from wp-config.php as soon as you are done, since the repair page does not require a login while that constant is set.
If a table will not check out clean after following the steps for its storage engine, or you are not confident about running server-level recovery yourself, contact us with the table name and what CHECK TABLE reported, and we can take it from there.
Frequently asked questions
What usually causes a table to become corrupted?
An unclean shutdown of the database process is the most common cause — the server ran out of disk space, was restarted mid-write, or a process was killed while a write was in progress. It is uncommon, and it is not something normal website traffic causes on its own.
Will repairing a table delete my data?
The purpose of REPAIR TABLE is to recover as much data as possible, not remove it. In a small number of severe cases a badly damaged row cannot be recovered and is dropped, which is exactly why backing up the database file first, where you are able to, matters before you run a repair.
Related reading
A blank page with one line of text, and five possible causes. Here is how to tell which one you have, in the order worth checking.
How to optimise a MySQL databaseOPTIMIZE TABLE reclaims space and refreshes statistics — but it behaves differently depending on the storage engine underneath.
How to restore a database from a backupThe database half of a restore has its own tools and its own common errors — here is how to do it properly.
How to back up a database on a scheduleA scheduled export you never have to remember to run is worth more than the best manual backup habit.