WordPress Troubleshooting

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.

WordPress database repair screen listing tables with OK and repaired status messages

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:

  1. Add define( 'WP_ALLOW_REPAIR', true ); to wp-config.php.
  2. Visit /wp-admin/maint/repair.php and choose Repair Database (or Repair and Optimize).
  3. 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 TABLE fixes 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 with innodb_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 check again.
  • Look at debug.log for 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_REPAIR enabled.
  • 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.

· Tutor LMS developers

Guides written and reviewed by the TutorLMS Expert development team. Every hook, function, table and setting we mention is checked against the Tutor LMS and Tutor LMS Pro source code before it is published.

Keep reading

Need a custom Tutor LMS solution?

Tell us what you are building or what is broken. A Tutor LMS developer reads every inquiry and replies with next steps and a free estimate.

Get a free Tutor LMS consultation

Tell us what you are building or fixing. A Tutor LMS developer replies with honest advice and next steps.

  • No obligation
  • Tutor LMS and Pro specialists
  • Your details stay private

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.