wpXpart

Error Fixes

How to Fix Error Establishing a Database Connection in WordPress (2026)

Fix Error Establishing a Database Connection in WordPress with 10 proven steps: check wp-config.php, test the connection, repair the database, replace core files, disable plugins and restore a backup.

wpXpart AgencyUpdated on November 22, 20269 min read
How to Fix Error Establishing a Database Connection in WordPress (2026)

You open your website and see one short line: Error Establishing a Database Connection. Your pages are gone, your visitors cannot reach you, and it can feel like the site has been wiped. The good news is that in most cases your content is still safe in the database, and the error can be fixed in a few minutes to an hour once you know where to look.

This guide explains what the error means, why it happens and 10 proven steps to fix it, from checking wp-config.php to repairing the database and restoring a backup.

Quick answer: The Error Establishing a Database Connection means WordPress cannot talk to its database. Work through these fixes in order: take a backup, check the database details in wp-config.php, test the connection, confirm the database server is running, repair the database, replace corrupted core files, disable plugins, check for a hack and, if needed, restore a backup or ask your host.
Diagram showing a visitor, WordPress and a database with a failed connection, plus four common causes: wrong credentials, database server down, corrupted tables and hosting limits or a hack
Illustration: WordPress cannot reach its database, and four common causes.

What does Error Establishing a Database Connection mean?

WordPress stores your posts, pages, settings and users in a database, usually MySQL or MariaDB. Every time someone visits a page, WordPress asks the database for the content. If that request fails, WordPress cannot build the page and shows this error instead. Your files are usually fine, and the problem is the link between WordPress and the database.

Common causes of the error

CauseHow to recognize itTypical fix
Wrong database detailsIt appears after a migration, a host change or editing wp-config.phpCorrect the name, user, password or host
Database server down or overloadedOther sites on the same host may also fail, and the problem may come and goContact your host and reduce resource usage
Corrupted database tablesThe admin area may show a repair messageRepair the database
Corrupted core filesIt happens after a failed update or uploadReplace the WordPress core files
Plugin or theme problemIt begins after installing or updating somethingDisable plugins and themes
Hosting limits or a full diskTraffic spikes or storage is fullUpgrade resources or clean up files
Hacked siteCredentials changed or unknown files appearedClean the site and restore a backup

Before you start

  • Take a backup. Use your hosting panel or a File Manager download. If the database is reachable, export it from phpMyAdmin.
  • Get access. You need your hosting control panel, and either FTP or the File Manager, so you can edit files without WordPress.
  • Check whether the whole site is down. Visit your home page, an inner page and /wp-admin to see which ones show the error.

How to fix Error Establishing a Database Connection: 10 steps

Six-step flow for fixing the WordPress database connection error: check wp-config.php, test the connection, check the database server, repair the database, replace core files and restore a backup
Illustration: a six-step path for fixing the error.

Step 1: Check whether the error is on the front end, the admin or both

If both the website and /wp-admin show Error Establishing a Database Connection, WordPress cannot connect at all, so continue with the steps below. If the front end shows the error but /wp-admin says that one or more database tables are unavailable, a table is damaged, so jump to Step 6 to repair the database.

Step 2: Check the database details in wp-config.php

The most common cause is a wrong detail in the wp-config.php file, which sits in the main folder of your WordPress installation. Open it with File Manager or FTP and check these four lines:

define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_user' );
define( 'DB_PASSWORD', 'your_password' );
define( 'DB_HOST', 'localhost' );
Code card showing the four wp-config.php database settings with placeholder values: DB_NAME, DB_USER, DB_PASSWORD and DB_HOST, and notes on what to check
Illustration: the four wp-config.php database lines to check, with placeholder values.

Compare each value with the database section of your hosting panel. Make sure the user is assigned to the database with full privileges, and check for typos, extra spaces and special characters in the password. Most hosts use localhost as the host, but some use a different server name, so check your host’s documentation. Save the file and reload the site.

Step 3: Test the database connection

Try to log in to phpMyAdmin with the same user and password. If you cannot log in, the credentials are wrong or the user has no access, so reset the database password in your hosting panel and update wp-config.php. If you are comfortable with code, you can also upload a tiny test file that tries to connect with the same details, and delete it right afterwards.

Step 4: Check that the database server is running

If your details are correct and you still see the error, the database server itself may be down or overloaded. Check your host’s status page, and ask support whether the database service is running and whether your account has reached a connection or resource limit. If it works again after a few minutes, a traffic spike or a heavy plugin may be the cause.

Step 5: Check that the database still has your data

Open phpMyAdmin and look at the database named in wp-config.php. You should see tables such as wp_posts and wp_options. If the database is empty or missing, a migration or a reset may have removed it, and you will need to import a backup.

Step 6: Repair the database

WordPress has a built-in repair tool. Add this line to wp-config.php, above the line that says to stop editing:

define( 'WP_ALLOW_REPAIR', true );

Then open yourwebsite.com/wp-admin/maint/repair.php and click Repair Database. Remove the line from wp-config.php as soon as you finish, because the repair page can be opened without logging in. You can also repair individual tables from phpMyAdmin.

Illustration of the built-in WordPress database repair page with Repair Database and Repair and Optimize Database buttons and a warning to remove the WP_ALLOW_REPAIR setting from wp-config.php afterwards
Illustration: the built-in WordPress database repair page.

Step 7: Replace the WordPress core files

Download a fresh copy of WordPress from WordPress.org and upload the wp-admin and wp-includes folders over the existing ones. Do not overwrite wp-content or wp-config.php, because they hold your themes, plugins, uploads and settings. This fixes damaged core files after a failed update.

Step 8: Disable plugins and switch to a default theme

Use FTP or File Manager to rename the plugins folder inside wp-content, for example to plugins-off. If the site connects again, rename the folder back and disable plugins one by one to find the cause. If needed, rename your active theme’s folder so WordPress falls back to a default theme.

Step 9: Check whether your site was hacked

If the details in wp-config.php changed without you touching them, or you see unknown files and users, your site may have been compromised. Change every password, scan for malware and restore a clean backup. Our WordPress security checklist explains exactly how to clean and protect a hacked site.

Step 10: Restore a backup or ask your host for help

If nothing works, restore the most recent clean backup of your files and database from your host or backup plugin. If you have no backup, ask your host to check the server logs. Hosts can often see errors that you cannot, such as a crashed database service or exhausted limits.

How to prevent the error from coming back

  • Keep daily backups, with one copy stored offsite, and test a restore.
  • Choose reliable hosting with enough resources for your traffic.
  • Keep WordPress, plugins and themes updated, and remove those you do not use.
  • Optimize your database from time to time and clear old revisions and spam.
  • Set up uptime monitoring so you hear about problems before your visitors do.
  • Be careful when you edit wp-config.php, and keep a copy of the original.
Checklist of eight habits that prevent WordPress database connection errors, including offsite backups, reliable hosting, updates, removing unused plugins, uptime monitoring and a tested restore plan
Illustration: a checklist to prevent database errors.

When to ask an expert for help

Call a professional if you do not have a backup, if your host cannot find the cause, if you suspect a hack, or if the site earns money and every hour of downtime costs you sales. At wpXpart we fix WordPress errors, repair and restore databases, remove malware and set up backups and monitoring. Explore our WordPress maintenance services and security solutions, or hire a WordPress expert.

Frequently asked questions

Did I lose my website content?

Usually not. The content is stored in the database, and the error means WordPress cannot reach it. After you fix the connection or restore a backup, your content normally comes back.

Why did the error appear suddenly?

Common reasons are a database server problem at your host, a traffic spike, a failed update, an edited wp-config.php file, corrupted tables or a hack.

Can a plugin cause this error?

Yes, a badly coded or overloaded plugin can exhaust database connections or damage data. Disable plugins to test.

What is the difference between this error and the white screen of death?

This error is specifically a failed database connection. The white screen of death is a blank page that is usually caused by a PHP error or memory limit, and you can learn how to fix the WordPress white screen of death in our separate guide.

Is it safe to use the WordPress repair tool?

Yes, but take a backup first and remove the repair line from wp-config.php when you finish.

Should I change my database password?

If you suspect a hack or you cannot log in to phpMyAdmin, yes. Update the password in your hosting panel and in wp-config.php at the same time.

How long does it take to fix?

Simple causes such as a wrong password take minutes. Server problems depend on your host, and restoring a large site from a backup can take longer.

How can I stop it from happening again?

Use reliable hosting, keep tested backups, update and clean up your plugins, and monitor your uptime.

Keep learning with these step-by-step guides from our team.

Conclusion

To fix Error Establishing a Database Connection, stay calm, take a backup and work through the checks in order: wp-config.php, the connection test, the database server, a repair, fresh core files, plugins, hack checks and finally a backup restore. Most sites are back online quickly, and good backups and reliable hosting keep the next incident small.

Stuck on this error? Start a project with wpXpart and we will get your WordPress site back online.

Share this article
Article bywpXpart Agency

The wpXpart team designs, builds, speeds up and supports WordPress websites, and shares practical guides along the way.

Need help with your WordPress site?

Tell us about your project and get a clear, written proposal.

Start a Project

Stay tuned with our latest updates

Subscribe for practical WordPress tips and news.

Scroll to Top