How to Repair a Corrupted WordPress Database
Recognise and repair a corrupted WordPress database: back up first, use WP_ALLOW_REPAIR, WP-CLI, phpMyAdmin or mysqlcheck, handle crashed MyISAM and InnoDB issues, and restore from backup when repair fails.

Signs of database corruption include "One or more database tables are unavailable", "Table is marked as crashed and should be repaired", missing content or errors in specific admin screens. To repair: take a backup, then run WordPress's built-in repair tool by adding define( 'WP_ALLOW_REPAIR', true ); to wp-config.php and visiting /wp-admin/maint/repair.php, or use wp db repair, phpMyAdmin's Repair table, or mysqlcheck. If repair fails, restore from the most recent good backup.
First: rule out a connection problem
"Error establishing a database connection" is usually credentials or a down database server, not corruption (database connection error). Repair is for tables that exist but are damaged.
Step 1: back up what you have
wp db export before-repair.sql
# or
mysqldump -u user -p dbname > before-repair.sql
If the export fails on a crashed table, back up the raw database files with your host's help.
Step 2: run a repair
WordPress repair tool:
- Add
define( 'WP_ALLOW_REPAIR', true );to wp-config.php. - Visit
/wp-admin/maint/repair.phpand choose Repair Database (or Repair and Optimize). - Remove the constant afterwards; the page works without login while it is set.
WP-CLI:
wp db check
wp db repair
mysqlcheck:
mysqlcheck -u user -p --auto-repair --check dbname
phpMyAdmin: select the tables, then "Repair table" from the dropdown.
MyISAM vs InnoDB
- MyISAM tables (older sites) can be marked "crashed" after a server crash;
REPAIR TABLEfixes most cases. Convert them to InnoDB afterwards. - InnoDB does not support
REPAIR TABLE; it recovers automatically on restart. Serious InnoDB corruption needs the host or DBA, sometimes withinnodb_force_recovery, and usually ends with a restore.
Step 3: check the site
- Load the front end and admin; check recent posts, orders and users.
- Run
wp db checkagain. - Look at
debug.logfor remaining database errors (debugging guide).
When repair fails: restore
Restore the latest good backup to a staging copy, compare, then restore to production. For stores and LMS sites, merge orders, enrolments and users created since the backup. This is why frequent, tested backups matter (backup strategy).
Prevent corruption
- Use InnoDB for all tables.
- Keep enough disk space; full disks cause failed writes.
- Avoid killing MySQL during writes; use proper shutdowns.
- Monitor database errors and back up daily (database maintenance).
Common mistakes
- Repairing without a backup.
- Leaving
WP_ALLOW_REPAIRenabled. - Running repair repeatedly on InnoDB expecting a change.
- Restoring an old backup over live orders without merging.
Frequently asked questions
Is the WordPress repair tool safe?
Yes, it runs standard MySQL check and repair commands. Back up first and remove the constant afterwards.
What causes database corruption?
Server crashes, full disks, hardware faults and interrupted writes, more often on MyISAM tables.
Can a plugin corrupt the database?
Plugins can write bad data, but table corruption is usually a server-level event.
How do I convert MyISAM to InnoDB?
ALTER TABLE wp_posts ENGINE=InnoDB; for each table, after a backup.
Conclusion
Back up, repair with WordPress, WP-CLI or mysqlcheck, verify, and restore if repair cannot recover the data. See the wp db repair reference and the MySQL REPAIR TABLE documentation. Course sites can also read our LMS database guide and slow query fixes; more on the roadmap.
Database damaged? Our database team can help recover it.
Save this practical guide
Add us as a preferred Google source, or ask an AI assistant to summarize this page and link back to the original guide when it is useful.
