WordPress repair database

Here Are the WordPress Database Repair Steps I Took Myself

· · 16 min read ·
Written By: author avatar Joella Dunn
author avatar Joella Dunn
Joella is a writer with years of experience in WordPress. At Duplicator, she specializes in site maintenance — from basic backups to large-scale migrations. Her ultimate goal is to make sure your WordPress website is safe and ready for growth.
·
Reviewed By: reviewer avatar John Turner
reviewer avatar John Turner
John Turner is the President of Duplicator. He has over 20+ years of business and development experience and his plugins have been downloaded over 25 million times.

Have you ever stared at your website, only to see a bunch of errors or a completely broken page?

One minute everything’s fine, the next, it’s like your site has a mind of its own.

Usually, when something like this happens, there’s an issue with your WordPress database. The database stores all of your important content, settings, and data, so it’s a very important part of your website.

WordPress database corruption isn’t nearly as scary as it seems. After years of managing WordPress sites, I’ve come to see it as just another fixable problem – like having a flat tire. Sure, it’s inconvenient, but once you know what you’re doing, you can get things rolling again.

I’m writing this guide because I wish I’d had something like it during my first database crisis.

We’ll walk through everything I’ve learned about fixing WordPress databases – from the quick wins that might get you back online in minutes to the more thorough solutions for trickier situations.

Let’s get your site back on track, shall we?

Table of Contents

When You Need to Repair Your WordPress Database

Database problems rarely appear out of nowhere. It usually gives you warning signs before it completely stops working.

The most obvious red flag is the “Error establishing a database connection” message. It’s like your website’s way of waving a big red flag saying, “Hey, we’ve got a problem here!”

Error establishing database connection

But there are subtler signs that I’ve learned to watch for over the years.

Here’s what you should be watching for:

Your site starts playing hide and seek with your content. One minute it’s there, the next it’s gone, only to reappear later. It’s a telltale sign your database needs attention.

The WordPress dashboard becomes extremely slow. If you’re clicking buttons and watching that loading spinner for what feels like forever, your database might be struggling to keep up.

You hit ‘save’ on a post, and nothing happens. Or worse, you spend an hour crafting the perfect page, hit publish, and poof – it’s all gone. Your database might be having trouble writing new information.

Random error messages pop up, especially ones mentioning “database connection”, “SQL errors,” or even the White Screen of Death. These are like your site’s way of sending up a distress flare.

The thing is, these issues rarely fix themselves. In fact, they usually get worse over time.

Understanding the common signs your WordPress database needs attention is crucial for maintaining optimal site performance.

But here’s the good news – catching these problems early makes them much easier to fix. And trust me, you want to fix them early.

Is Your Database Broken or Just Bloated?

Before running any repair, it helps to know which problem you actually have. Broken and bloated databases produce similar symptoms, but they need different fixes.

Signs your database is broken:

  • “Error establishing a database connection” appears on the front end or in the admin
  • White Screen of Death with no other error message
  • Posts or pages disappear after publishing
  • SQL error messages appear in the WordPress dashboard
  • The site loads intermittently, then fails

Signs your database is bloated:

  • The admin dashboard is noticeably slow with no error messages
  • Backup file sizes are much larger than they should be
  • Queries time out under normal traffic loads
  • Performance has degraded gradually over months with no clear cause

Some sites have both problems at once. A database can be structurally damaged and cluttered with years of accumulated revisions and expired cache data.

What Causes Database Corruption?

You know what question I hear most often when helping people with database issues? “What did I do wrong?”

Usually, it’s not something you did at all. In my experience, database corruption is often like catching a cold. Sometimes it just happens, even when you’re doing everything right.

From my years of fixing sites, here are the most common WordPress database errors I’ve encountered:

Your hosting provider’s server had a bad day. Maybe it was a power fluctuation, or maybe it ran out of resources during a traffic spike. When servers hiccup during database operations, things can get messy.

That plugin update you just installed? Sometimes plugins don’t play nice with each other or with WordPress core. These plugin conflicts can cause database problems.

Remember that time you were editing a post and your internet connection dropped? If the connection cuts out while WordPress is saving data to the database, it can leave things disconnected.

And sometimes, it’s just wear and tear. Databases are like any other tool – they can get cluttered and fragmented over time. I’ve seen sites slow to a crawl simply because their database tables are disorganized.

Here are some other reasons why your database might be corrupted:

  • A hacked site can cause severe damage like malware, viruses, and other bad code
  • WordPress database credentials issue preventing proper access
  • Exhausted memory limit
  • Hardware failures and other server issues
  • Software bugs or WordPress plugin conflicts

Before Repairing Your WordPress Database

I’m about to share something that might save your website and your sanity.

Here’s my golden rule of database repair: Never, ever start fixing things without a backup.

I don’t care if your site is on fire; save a backup first. It’s like having a save point in a video game. If things go south, you can always return to where you started.

Creating a backup now could save you hours (or days) of headaches later. Here’s what you need to back up:

  • Your database (obviously) – even if it’s corrupted. A partially corrupted database is better than no database at all.
  • All your WordPress files – themes, plugins, uploads, everything. Sometimes fixing database issues requires reinstalling WordPress, and you’ll want your files safe and sound.

This is where a tool like Duplicator becomes your best friend. I’ve used it countless times to create complete backups of sites before diving into repairs. It’ll give you a safety net while you work on fixing the issue.

Duplicator Pro plugin

Before getting started, create a new backup. Choose the Full Site preset for a complete backup.

Full site backup preset

For extra security, save the backup to a cloud storage location. Duplicator supports all of these options:

  • Duplicator Cloud
  • Google Drive
  • Dropbox
  • Microsoft OneDrive
  • Amazon S3
  • Wasabi
  • Google Cloud
  • DreamObjects
  • Vultr
  • DigitalOcean Spaces
  • Cloudflare R2
  • Backblaze B2
  • Any other S3-compatible cloud storage

Plus, you can select multiple locations if you’re worried one will fail.

Backup storage locations

Now you’re ready to troubleshoot!

If you need help deciding, here’s my review of the best WordPress backup plugins available.

How to Repair a WordPress Database

When you need to repair the WordPress database, there are several easy methods available. Let’s explore them all!

Restore a Clean Database Backup

Let me tell you about a recent crisis. Black Bike Media had to resolve their client’s 2.4GB corrupted database. A server outage took out valuable information in this job search website’s database tables.

Because they had Duplicator Pro set up for backups, Black Bike had their site back up and running in minutes. No all-nighter required.

Here’s why restoring a backup is often your best first move:

  • It’s predictable. You know exactly what you’re getting – your site as it was when the backup was made.
  • It’s comprehensive. You’re not just patching problems; you’re restoring to a known good state.
  • It’s fast. Much faster than trying to diagnose and fix corruption issues piece by piece.

Now, if you’re using Duplicator Pro (which I highly recommend), the restoration process is surprisingly straightforward.

Log into your WordPress dashboard (if you can’t, you can upload the backup directly to your server).

Go to Duplicator Pro » Backups. Find your most recent backup before the problems started. Click the Restore button.

Restore Duplicator backup

But what if you don’t have a backup? First, take a deep breath. I’ve been there too, and while it’s not ideal, it’s not game over. We’ve got several other methods up our sleeve.

Check Your Database Credentials

Your database stores its credentials in the wp-config.php file. If these are incorrect, it’ll lead to connection errors.

When your WordPress database needs repairs, first check the database credentials in your wp-config.php file. You may just need to update them.

Open your wp-config.php file using cPanel or an FTP client. Look for this information:

  • DB_NAME (The name of your database)
  • DB_USER (Tthe username for your database)
  • DB_PASSWORD (The password for your database)
  • DB_HOST (The hostname for your database server)

Your web hosting provider will know what these values are supposed to be. You can reach out to support or find this information in your database settings.

Database credentials

Enable Error Logs

Error logs can be a goldmine of information. They provide clues to the source of your database corruption.

To enable error logging in WordPress, you’ll need to add some code to your wp-config.php file. Remember, you’ll need an FTP or file manager to do this.

Add these lines of code to your wp-config.php file:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

define( 'WP_DEBUG', true ); enables debugging mode.

define( 'WP_DEBUG_LOG', true ); tells WordPress to log errors to a file.

define( 'WP_DEBUG_DISPLAY', false ); will hide errors from displaying on the front end of the website.

After you add these lines, a debug.log file will be created. It will be in your wp-content folder.

Check this file after making changes to your database. It’ll show you any errors or warnings.

Once you’re done debugging, don’t forget to disable error logging. You can do this by removing these lines of code. Keeping it enabled when it is not needed can slow down your site.

Use phpMyAdmin to Repair WordPress Database Tables

I still remember my first time using phpMyAdmin. Those rows of database tables looked like something from The Matrix.

But here’s the thing: once you know what you’re looking at, it’s actually pretty straightforward. Think of it as your database’s control room.

Here’s my step-by-step guide to using phpMyAdmin to repair your database (don’t worry, I’ll keep it simple).

Log into your hosting control panel (usually cPanel). Find and click on phpMyAdmin.

WordPress phpMyAdmin

Select your WordPress database from the left sidebar. Check all tables. From the dropdown menu, select Repair table.

Repair database with phpMyAdmin

PhpMyAdmin will attempt to fix your corrupted database tables.

Use a Database Repair Plugin

Sometimes the simplest solution is the best one. Several database repair plugins are available to help fix and optimize database tables. I’ve had great success with them, especially when helping clients who aren’t comfortable with phpMyAdmin.

Just remember my golden rule: backup first! Even with a user-friendly plugin interface, we’re still performing surgery on your database.

One of my favorite plugins for database repairs is DB Optimizer. It gives you a database health score and allows you to optimize or repair any of your tables.

DB Optimizer plugin

Once installed, find DB Optimizer » Tables. Use the Repair buttons next to the tables you need fixed.

DB Optimizer repair database

DB Optimizer will attempt to fix any existing database issues.

Use the WordPress Database Repair Tool

The built-in WordPress database repair tool can be incredibly useful for addressing common database issues. It’s just hidden by default.

Think of it as your site’s built-in first aid kit. While it’s not as comprehensive as a full backup restore, I’ve seen it fix plenty of minor database corruptions.

First, we need to enable it. Open your wp-config.php file and add this line at the bottom:

define('WP_ALLOW_REPAIR', true);

Now, visit this URL on your site:

your-site.com/wp-admin/maint/repair.php

You’ll see two options: Repair Database and Repair and Optimize Database.

Repair WordPress database

Try Repair Database first. If that doesn’t help, go for Repair and Optimize. This is more thorough but takes longer.

A word of caution from someone who learned the hard way: remove that line from wp-config.php when you’re done. Otherwise, anyone can access your repair page, and that’s not something you want.

Use cPanel to Repair Your Database

If your hosting provider has cPanel, you’ll have built-in database repair functionality. This is a convenient way to repair your database if your host supports it.

The exact steps to access these tools will depend on your specific hosting provider. For Bluehost, open cPanel and find MySQL Databases.

MySQL databases

Now, go to the Modify Databases section. Select the database you want to repair. Then, hit the Repair Database button.

Repair database with cPanel

This can be a quick and easy option for some. It’s worth checking if your host offers this.

Use WP-CLI to Repair Your Database

If you’re comfortable with command line interfaces, WP-CLI is a great tool for WordPress. It allows you to perform many WordPress tasks from the command line.

Here’s the basic WP-CLI command for database repair:

wp db repair

WP-CLI processes each table and prints the result in the terminal. The output lists every table followed by its repair status.

You will know this worked when every table in the output shows “repaired” or “OK.” Any entry showing “error” needs individual attention.

What I love about WP-CLI is its efficiency. No clicking through menus, just straight to the point. Plus, it gives you detailed feedback about what it’s fixing.

What to Do After Repairing Your Database

Repairing tables fixes the structural damage. But a repaired database can still be slow, oversized, and inflating your backup sizes.

If your dashboard is sluggish after a repair, or your backups are larger than they should be, the database needs optimization. This is where DB Optimizer comes in.

DB Optimizer is Duplicator’s database maintenance tool. It scores your database health from 0 to 100, shows exactly what is slowing things down, and cleans it up without requiring you to write SQL or dig through phpMyAdmin.

DB Optimizer plugin

The main screen shows a health score with a color-coded grade: green (80-100) means the database is in good shape, yellow (50-79) means attention is needed, red (below 50) means significant cleanup is overdue.

DB Optimizer health score

The score evaluates five categories (table overhead, expired transients, post revisions, autoload data size, and trash) and flags each one individually so you know exactly where the problem is.

Once you see which categories are flagged, DB Optimizer shows the item count and reclaimable disk space for each one before any deletion runs. Review the numbers, then run cleanup on each flagged category.

DB Optimizer cleanup

The payoff beyond speed. A smaller database builds faster backups and transfers faster during a migration.

Frequently Asked Questions (FAQs)

How do I fix a database in WordPress?

You can fix a WordPress database by accessing your hosting control panel and running the repair tool in phpMyAdmin. Alternatively, add define('WP_ALLOW_REPAIR', true); to the wp-config.php file, then visit yourwebsite.com/wp-admin/maint/repair.php to repair and optimize the database.

How do I clean up a WordPress database?

Clean up a WordPress database by deleting unused plugins, themes, and revisions. Use a plugin like WP-Optimize to remove spam comments, transient options, and orphaned metadata. Regularly back up the database before cleaning to prevent data loss.

Regular database optimization can prevent many common issues before they become serious problems!

Can you restore a WordPress database?

Restore a WordPress database by accessing your hosting control panel, navigating to phpMyAdmin, and using the “Import” feature to upload a backup file. Alternatively, use a backup plugin like Duplicator to restore the database directly from a saved backup.

Restore database backup

How do I restore my WordPress database without a backup?

Restore a WordPress database without a backup by contacting your hosting provider to check for server-level snapshots or recovery options. If unavailable, use database repair tools in phpMyAdmin to recover partial data or attempt to rebuild the database using cached content from your site.

What causes a WordPress database to get corrupted?

Most corruption happens during an interrupted write operation. A server crash or power failure while WordPress is saving data leaves a table in a partially written state. Plugin conflicts that run malformed SQL queries can also corrupt rows over time.

Other causes include hardware failures on the host’s storage layer, security breaches that introduce malicious database modifications, and interrupted file transfers during a migration. Normal day-to-day WordPress use rarely causes corruption on its own.

Will repairing my database delete any content?

Repair does not delete content. It fixes the structural integrity of existing database tables without touching the data inside them. Optimization is where data gets removed, specifically revisions, expired transients, spam, and fragmented overhead space. DB Optimizer shows item counts and reclaimable space before any deletion runs, so you can review exactly what will be removed before confirming. Nothing runs without your approval.

What is the difference between repairing and optimizing a WordPress database?

Repair fixes structurally broken or crashed database tables. It addresses database connection errors, corrupted rows, and table-level damage that prevents WordPress from reading or writing data. Optimization removes accumulated clutter from tables that are structurally healthy but bloated: post revisions, expired transients, spam comments, and fragmented overhead space.

A repaired database can still be slow and oversized if it has never been optimized. Both tasks belong in a regular maintenance routine.

Your Database Is Fixed. Here’s How to Keep It That Way

If you worked through the steps above, you’ve done more than fix a broken database. You repaired the structural damage, identified whether the problem was corruption or bloat, and ran optimization to bring the health score into the green. The database that caused the original error is now cleaner and smaller than it was before the problem started.

Going forward, set a monthly reminder to open DB Optimizer and check the health score. Five minutes, once a month.

Anything below 80 is worth a cleanup run. A score that stays in the green with monthly checks means this problem almost certainly doesn’t come back, because you’re removing the clutter before it accumulates to a level that causes real damage.

More than 1.5 million WordPress professionals use Duplicator to protect their sites with automated backups, cloud storage connections, and one-click restores. If something goes wrong, the disaster recovery URL gets your site back without needing WordPress to be functional first.

DB Optimizer is included in Duplicator Pro and Elite plans, so the backup and the ongoing database health monitoring live in the same dashboard.

While you’re here, I think you’ll like these other WordPress guides:

author avatar
Joella Dunn Content Writer
Joella is a writer with years of experience in WordPress. At Duplicator, she specializes in site maintenance — from basic backups to large-scale migrations. Her ultimate goal is to make sure your WordPress website is safe and ready for growth.
Our content is reader-supported. If you click on certain links we may receive a commission.

Don't Let Another Day Pass Unprotected

Every hour without proper WordPress backups puts your site at risk • Every delayed WordPress migration costs you performance and growth

Get Duplicator Now
Duplicator Plugin

Wait! Don't miss your
exclusive deal!

As a customer, you get 60% OFF

Try Duplicator free on your site — see why 1.5M+ WordPress pros trust us. But don't wait — this exclusive 60% discount is only available for a limited time.

or
Get 60% Off Duplicator Pro Now →