WordPress Database Connection Error: 8 Fixes That Reconnect Your Site

Laptop showing a blank white error page with the TechSBSInfo logo at top left, illustrating a wordpress database connection error
A blank white error page on a laptop in a server room — the classic sign of a wordpress database connection error.

Seeing the words “Error establishing a database connection” on your site is alarming. Your pages vanish. Your visitors see a plain white screen. And it looks like everything is broken. The good news is that a wordpress database connection error is one of the most fixable problems in WordPress. In most cases, the cause is small — a wrong password in a config file, a database server having a bad moment, or a table that needs a repair. This guide walks you through 8 fixes in order, from the simplest checks to the last-resort options, so you can reconnect your site step by step.

Quick Checks

  • Try reaching your WordPress dashboard. Go to yoursite.com/wp-admin. If the dashboard loads but the front end shows the error, your database is probably corrupted — skip to Fix 6.
  • Confirm the error is real, not your browser. Open the site on your phone or in a private window. If pages will not load in any browser, check our guide on Chrome pages not loading to rule out a browser problem first.
  • Think about what changed recently. Did you migrate hosts, change a hosting password, or install a new plugin? The answer points straight at the cause.
  • Check your hosting account’s status page. If the database server is down, every site on that server fails at once — and only your host can fix it.
  • Do not panic and do not start deleting things. A wordpress database connection error almost never means your content is gone. Your posts and pages are still sitting in the database.
  • Make a backup before you touch anything. Download a copy of wp-config.php and, if you can, a database export from your hosting panel. You will need them if a fix goes wrong.

Diagnose Table

SymptomLikely causeGo to fix
Error appears right after moving hosts or changing a passwordWrong database credentials in wp-config.phpFix 3
Error on both the site and wp-admin, host status page shows an incidentDatabase server down or overloadedFix 2
wp-admin works but the front end shows the errorCorrupted database tablesFix 6
Error started after editing wp-config.php by handTypo or stray characters in the fileFix 4
phpMyAdmin shows the database missing or “access denied”Database deleted or user lost its privilegesFix 5
Error appeared after a migration, credentials look rightWrong DB_HOST value or table prefix mismatchFix 7
Nothing above works and you have a backupRestore the database from backupFix 8

1. Check Whether wp-admin Still Works

This is the fastest diagnostic you have. It costs nothing and changes nothing.

  1. Type yoursite.com/wp-admin into your browser (replace yoursite.com with your real domain).
  2. Watch what happens. There are two possible outcomes.
  3. If the login page appears, your database credentials are fine. WordPress can reach the database, because the dashboard needs the database to load. The problem is more likely corrupted tables affecting the front end. Move on to Fix 6.
  4. If the same error appears, WordPress cannot connect to the database at all. The cause is usually wrong credentials or a database server problem. Continue with Fix 2.

This one check saves you from editing files you do not need to edit.

2. Check Your Host’s Server Status Page

Before you change a single file, rule out a server problem. A wordpress database connection error is often not your fault at all.

  1. Open your hosting provider’s status or network page in a new tab. Most hosts publish one, and many also post updates on their social accounts.
  2. Look for any reported incident involving MySQL, MariaDB, or database servers.
  3. Ask yourself: are other sites on the same host failing too? If a friend’s site on the same host shows the same error, the whole database server is down.
  4. If there is an incident, stop here and wait. Contact your host’s support if you want an estimated fix time, but do not edit your files — the problem will clear when the server recovers.
  5. If the status page shows everything healthy, the problem is inside your own site. Continue to Fix 3.

Why this matters: editing wp-config.php during a server outage changes nothing and can introduce new mistakes. Always check the server first.

Hosting control panel dashboard on a laptop, used to check database status when fixing a wordpress database connection error
Your hosting control panel is where you check server status, databases, and phpMyAdmin.

3. Verify the Database Credentials in wp-config.php to Resolve the WordPress Database Connection Error

Wrong credentials are the single most common cause of this error. They break most often after a site migration or after a hosting password change. WordPress stores four values in wp-config.php:

  • DB_NAME — the name of your database
  • DB_USER — the database username
  • DB_PASSWORD — the database password
  • DB_HOST — the database server address (often localhost)

If any one of them is wrong, WordPress cannot log in to the database, and you get the error.

Back up first. Before editing, download a copy of wp-config.php to your computer. If you make a mistake, you can restore it in seconds.

  1. Open your hosting control panel and launch its File Manager (or connect with an FTP client).
  2. Find wp-config.php in your site’s root folder — the same folder that contains wp-admin and wp-content.
  3. Download a copy to your computer as a backup. This step is not optional.
  4. Open wp-config.php for editing and find these four lines:
   define( 'DB_NAME', 'your_database_name' );
   define( 'DB_USER', 'your_database_user' );
   define( 'DB_PASSWORD', 'your_database_password' );
   define( 'DB_HOST', 'localhost' );
  1. Now open your hosting panel’s MySQL Databases (or Databases) section and compare. Check the exact database name, the exact username linked to it, and re-enter the password carefully.
  2. Re-type the password by hand rather than pasting it. Pasted passwords often carry invisible spaces, and one invisible space is enough to break the connection.
  3. Confirm DB_HOST. On most shared hosting it is localhost, but some hosts use a different address. Your host’s documentation or database section shows the correct value.
  4. Save the file, then reload your site.

If the error disappears, you are done. If it stays, the credentials were not the problem — continue.

Code editor showing a configuration file while checking credentials to fix a wordpress database connection error
Double-checking DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php.

4. Look for Stray Characters in wp-config.php

This fix takes two minutes and catches a sneaky cause: invisible characters in wp-config.php that break the file before WordPress can even read your credentials.

  1. Open wp-config.php in a plain-text editor (Notepad, VS Code, or your host’s File Manager editor — never a word processor).
  2. Scroll to the very top of the file. The first characters must be <?php with nothing before them — no spaces, no blank lines, no hidden characters.
  3. Scroll to the very bottom. Many copies of the file end with ?> followed by blank lines. A blank line after the closing tag sends output to the browser too early and can trigger strange errors. Deleting the closing ?> entirely is safe and is actually what WordPress itself recommends.
  4. Look for any odd symbols or duplicated lines around the database defines, especially if you edited the file recently.
  5. Save and reload your site.

Hand-edited config files are a classic source of this error. A single stray space before <?php is invisible in most editors but very real to PHP.

5. Confirm the Database Exists and the User Has Privileges

Sometimes the credentials in wp-config.php are correct, but the database itself is missing or the user no longer has permission to reach it. This can happen after a failed migration, a hosting account change, or an accidental deletion.

  1. In your hosting control panel, open phpMyAdmin.
  2. Look at the database list on the left. Find the database name from DB_NAME.
  3. If the database is missing, it may have been deleted or never imported. Restore it from a backup (see Fix 8) or re-import your database export.
  4. If the database exists, click on it and confirm the tables are there. You should see tables like wp_posts, wp_options, and wp_users (the prefix may differ).
  5. Go back to your hosting panel’s MySQL Databases section. Check that your DB_USER is listed as a user of that database with all privileges ticked.
  6. If the user is missing or its privileges were reduced, re-add the user to the database and grant all privileges.
  7. Reload your site and test.
Glowing database cylinders beside a server rack, showing the tables WordPress needs when fixing a wordpress database connection error
The database and its tables must exist with the right privileges before WordPress can connect.

If phpMyAdmin itself shows “access denied”, the problem sits with your hosting account, not WordPress — contact your host’s support with that exact message.

6. Repair Corrupted Database Tables

If wp-admin loads but your site’s front end shows the error, corrupted tables are the prime suspect. WordPress ships with a built-in repair tool for exactly this situation. Use it carefully: it is powerful, and it must not be left switched on.

Back up your database first. Export a copy from phpMyAdmin before running any repair. A repair changes your data, and you want a way back.

  1. Open wp-config.php and add this line just above the comment that says /* That's all, stop editing! Happy publishing. */:
   define( 'WP_ALLOW_REPAIR', true );
  1. Save the file.
  2. Visit yoursite.com/wp-admin/maint/repair.php in your browser.
  3. You will see a simple page with two buttons: Repair Database and Repair and Optimise Database. Click Repair Database first.
  4. Wait for the process to finish. It lists each table and its result. Note any table it could not repair.
  5. Reload your site and check whether the error is gone.
  6. Now remove the line you added. Open wp-config.php and delete define( 'WP_ALLOW_REPAIR', true );, then save.

That last step is critical. The repair page needs no login. Anyone who finds its address can run repairs on your database while the line is present. Switch it on, run the repair, and switch it off immediately — every time.

Wrench beside a glowing database symbol representing the repair process for a wordpress database connection error
The built-in repair tool fixes damaged tables — remember to switch it off afterwards.

7. Fix Post-Migration Mismatches

Migrations cause this error even when the credentials look right, because two other settings often change silently when a site moves hosts.

The DB_HOST value. Your old host may have used localhost while the new one uses a specific address like mysql.examplehost.com. Check the new host’s documentation and update DB_HOST to match.

The table prefix. WordPress reads this line in wp-config.php:

$table_prefix = 'wp_';

The prefix must match the actual tables in your database. If your backup used wp_ but the new install created wp2_, WordPress looks for tables that do not exist and throws the connection error.

  1. Open phpMyAdmin and look at your table names. Note the real prefix (everything before posts, options, users).
  2. Open wp-config.php and compare it with $table_prefix.
  3. If they differ, change $table_prefix to the real prefix and save.
  4. Reload your site.

Also re-check DB_NAME, DB_USER, and DB_PASSWORD after any migration — database names and usernames often gain a new prefix on the new host (for example newhost_wpdb instead of wpdb).

8. Restore From a Backup or Ask Your Host

If none of the fixes above worked, you are dealing with something deeper: a badly damaged database, a server-level fault, or credentials that no one can verify. This is the point to stop experimenting and use your safety net.

  1. Restore your most recent backup. Most hosting panels offer one-click restores of both files and databases. Restore the database to a point before the error appeared.
  2. If you keep your own backups, import the database SQL file through phpMyAdmin’s Import tab.
  3. Contact your host’s support if you have no backup. Describe exactly what you tried: the error text, that wp-admin does or does not load, and that the credentials check out. Ask them to check the database server logs and to restore the database from their own server backups — most hosts keep these.
  4. While you wait, you can enable WordPress debug mode to capture the real error message for support. Add these lines to wp-config.php:
   define( 'WP_DEBUG', true );
   define( 'WP_DEBUG_LOG', true );

Then reproduce the error and read wp-content/debug.log. The official WordPress debugging guide explains what each message means. Remove or set these back to false when you are done — debug output should never stay on a live site.

Restoring a backup feels drastic, but it is faster and safer than a tenth round of guessing. And if your host restores from their own copies, you may lose nothing at all.

What to Avoid

  • Never delete database tables to “fix” the error. Deleting tables destroys content. The error means WordPress cannot reach the database, not that the tables should be removed.
  • Never leave WP_ALLOW_REPAIR enabled. The repair page needs no login. Remove the line the moment your repair finishes.
  • Never edit wp-config.php without a backup. One wrong character can take your site down. Download a copy first, every time.
  • Do not paste your database password into public forums or comment sections. If you need help, share the error text and what you tried — never credentials.
  • Do not install random “database fixer” plugins while the site is down. You cannot reach wp-admin to install them properly anyway, and shady plugins can make things worse.
  • Do not change the table prefix on a live site on a guess. A wrong prefix disconnects WordPress from every table at once. Verify the real prefix in phpMyAdmin first.

FAQ

What does “Error establishing a database connection” actually mean?

It means WordPress tried to talk to its MySQL or MariaDB database and failed. Your posts, pages, settings, and user accounts all live in that database, so when the connection fails, WordPress has nothing to display and shows this plain message instead.

Can I still log in to wp-admin when this error appears?

Sometimes. If the dashboard loads while the front end shows the error, the connection works but some tables are damaged — run the repair in Fix 6. If wp-admin shows the same error, the connection itself is broken — start from Fix 1.

Will I lose my content?

Almost certainly not. A wordpress database connection error is a connection problem, not a data-deletion problem. Your content is still in the database in the vast majority of cases. That said, always keep backups — they are your guarantee, not your hope.

How do I know whether it is my host’s fault?

Check the host’s status page for database incidents, and ask whether other sites on the same host are failing. If the whole database server is down, every affected site shows the same error at the same time. In that case only the host can fix it, so save your energy and contact support.

Is the built-in database repair tool safe?

Yes, when used correctly. Back up the database first, add the WP_ALLOW_REPAIR line, run the repair, then remove the line immediately. The danger is not the tool — it is leaving the repair page open to the public internet.

What should I do if none of the 8 fixes work?

Restore from a backup, then contact your host with full details of what you tried. Enable WP_DEBUG and WP_DEBUG_LOG temporarily so support can see the real underlying error in wp-content/debug.log. The official WordPress troubleshooting FAQ also covers edge cases beyond these eight fixes.

Conclusion

A wordpress database connection error looks catastrophic but is usually a small, specific problem: wrong credentials, a grumpy database server, or a table that needs repairing. Work through the fixes in order, back up before each change, and resist the urge to delete or reinstall things at random. Most readers will have their site back by Fix 3 or Fix 6.

If this guide helped, explore more troubleshooting on our blog, learn what we do on the about page, or start from the homepage to browse every guide by category.

Leave a Reply

Your email address will not be published. Required fields are marked *