A damaged or poorly functioning WordPress database can cause missing content, login problems, slow pages, failed updates and database table errors. Before attempting any repair, confirm that the database is actually the problem. Many connection errors are caused by incorrect credentials, a stopped database server or exhausted hosting resources instead of corrupted tables.
Back up the website first
Create a complete backup of both the database and website files before making changes. Download the backup to an off-site location and confirm that it can be restored. A database repair changes live data, so this step is not optional.
Identify the database symptoms
Check the exact error message, when it began and which parts of the site are affected. Review the PHP error log and hosting database logs when available. Common signs include messages about crashed tables, tables marked for repair, failed database queries or wp-admin pages that cannot load data.
If WordPress shows “Error establishing a database connection,” start with my database connection error guide. That error does not automatically mean the database is corrupted.
Use the built-in WordPress repair tool
WordPress includes a database repair screen that is disabled by default. Add the following line to wp-config.php above the line that says to stop editing:
define( 'WP_ALLOW_REPAIR', true );
Then visit yourdomain.com/wp-admin/maint/repair.php. Choose either Repair Database or Repair and Optimize Database. Repair is the safer first choice. Optimization may take longer on a large site.
The repair screen does not require a WordPress login while enabled. Remove the WP_ALLOW_REPAIR line immediately after finishing.
Repair tables in phpMyAdmin
In cPanel, open phpMyAdmin, select the correct WordPress database and review the table list. Select only tables reporting a problem, choose Repair table and wait for the result. Do not run random SQL commands or modify table data unless you understand the consequences.
The repair command mainly applies to supported MyISAM tables. Modern WordPress databases commonly use InnoDB, where recovery may require hosting support or restoring a clean backup.
Check database credentials and permissions
Confirm the database name, username, password and host in wp-config.php. Also confirm that the database user has the required permissions. Incorrect credentials can look like database damage but cannot be fixed by repairing tables.
Review plugins and database growth
Plugins can create custom tables, large autoloaded options and repeated failed queries. Check which tables are unusually large and identify the plugin that owns them before deleting anything. Deactivating a plugin does not necessarily remove its data.
Use Query Monitor or hosting performance tools to find slow queries. If wp-admin is also sluggish, follow my slow WordPress admin troubleshooting guide.
Restore a backup when repair fails
Restore a known-good database backup when corruption is extensive, repair commands fail or important rows are missing. Compare the backup date against new orders, form entries, users and content that may be overwritten. On an ecommerce or membership site, coordinate the restoration with the host.
Prevent future database problems
- Maintain automatic off-site backups.
- Keep WordPress, plugins and themes updated.
- Monitor disk space and database size.
- Avoid interrupting migrations, imports and database updates.
- Remove abandoned plugins after confirming their data is no longer needed.
- Use staging for database search-and-replace work.
Database repair should be evidence-based. Back up first, fix only the affected component and document every change.
