Error Establishing a Database Connection? Fix It In 10 Mins

Bulletproof Backups for Your WordPress Website

Fortify your business continuity with foolproof WordPress backups. No data loss, no downtime — just secure, seamless operation.

Error Establishing a Database Connection feature image

You open your site and see Error Establishing a Database Connection message. It is a rough moment, but it is usually fixable. In most cases, your posts, pages, and media are still there. WordPress just cannot reach the database that stores them.

This WordPress error usually comes from one of five issues: bad database credentials, a hosting problem, a faulty plugin or theme, damaged WordPress files, or a corrupted database. 

The good news is that this is a familiar WordPress problem, which means there is a clear way to troubleshoot it. We will help you narrow down the cause quickly and get your site back on track without unnecessary guesswork.

TL;DR: To recover from error establishing a database connection in WordPress, a recent backup is your fastest safety net, especially if a backup plugin is already handling restores for you. Once the site is stable, check the database credentials, disable plugins and themes, replace damaged files, repair the database, and ask your host to verify the database server.

What is the Error Establishing a Database Connection

Error establishing a database connection

The Error establishing a database connection message means WordPress cannot connect to your site’s database.

Your WordPress site depends on two things working together: the files and the database. The files run the code. The database stores your content, user accounts, settings, and plugin data. If WordPress cannot reach that database, it cannot build the page, so the site stops loading.

That connection depends on four values in your wp-config.php file:

edit-wp-config-file database details
  • DB_NAME
  • DB_USER
  • DB_PASSWORD
  • DB_HOST

If one of those values is wrong, or if the database server is down, WordPress throws this error.

The technical reason is simple. The practical question is what broke the connection. That is what we will fix next.

What causes it

This error usually comes from one of a few familiar places, and each one points to a specific fix.

If the database credentials in wp-config.php are wrong, WordPress cannot log in to the database. This often happens after a: 

  • Migration
  • Host change
  • Password reset
  • Manual edit

If the database server is having issues, WordPress may have the right credentials and still fail to connect. This is common on shared hosting during traffic spikes or maintenance.

  • If a plugin or theme is buggy, it can break WordPress badly enough to trigger a database connection error. This often happens right after an update.
  • If core files are damaged, WordPress may fail before it can complete the database request. Failed updates, malware, and manual edits are common reasons.
  • If the database itself is corrupted, WordPress may connect but fail to read what it needs. In that case, repairing the database can fix it.

We are going to pair each cause with the fix, so you do not have to jump around the page or guess what to try first.

Troubleshooting

Start with the fix that gets your site back fastest. Then work through the causes in a sensible order. That keeps downtime low and avoids the usual trap of changing too many things at once.

Restore your site

If you have a clean, recent backup, restoring your site is the fastest way to get live again.

Restore backup new UI BV

This does not always tell you what caused the error, but it does get your site back while you sort out the root issue. If your site brings in sales, leads, or bookings, that matters.

If you do not have a backup, or you want to fix the root issue right away, start with the database credentials.

Check WordPress database credentials

This is the most common cause of the “Error Establishing a Database Connection” in WordPress, especially after a migration or host change.

You need access to your site files and your hosting dashboard.

Open wp-config.php. Use FTP, SFTP, or your host’s File Manager to open the root folder. Look for wp-config.php in the same folder as wp-admin, wp-content, and wp-includes.

public_html on FTP

Find the database settings. You are looking for these lines:

define('DB_NAME', 'database_name_here');

define('DB_USER', 'username_here');

define('DB_PASSWORD', 'password_here');

define('DB_HOST', 'localhost');

Check your hosting panel. Find the actual database name, username, password, and host in cPanel or your hosting dashboard. On many hosts, this is under MySQL Databases or a similar section.

Compare each value. Check the values in wp-config.php against the real ones, one by one. Do not guess. A single typo is enough to break the connection.

edit-wp-config-file database details

Confirm DB_HOST. Many sites use localhost, but not all do. If you are unsure, ask your host for the correct database host. Correct any mismatch, save the file, upload it if needed, and test the site.

A common mistake here is resetting the database password in the host panel and forgetting to update wp-config.php. If that happened, this fix usually solves the problem straight away.

If the credentials are correct and the error remains, the next thing to check is whether a plugin or theme caused it.

Check if a plugin or theme is causing the error

If the error showed up after an update, installation, or file edit, a plugin or theme could be behind it.

You can test this even if wp-admin is down via WordPress FTP.

Access the Plugins Folder

Disable all plugins. Go to the wp-content folder in your site root. Rename the plugins folder to something like plugins-disabled. This deactivates all plugins at once.

If the site loads, a plugin caused the issue. Rename the folder back to plugins.

Check plugins one by one. Rename each plugin folder individually and test the site each time until the problem returns. That identifies the faulty plugin.

Leave the bad plugin disabled. If the plugin broke the site after an update, roll it back or replace it. If support is poor and updates are inconsistent, replacing it is often the better call.

If plugins are not the issue, test the theme.

theme in themes folder

Disable the active theme. Rename the active theme’s folder inside themes. If a default WordPress theme is installed, WordPress should switch to it automatically. If the site comes back, the theme is the problem.

Replace or reinstall the theme. Use a fresh copy from the original source. If you edited the theme directly, undo those changes or move them into a child theme later.

If plugins and themes are not the cause, it is time to check the core files.

Replace corrupt files

Damaged WordPress files can stop the site before the database connection completes.

This often happens after a failed update, malware infection, or manual file edit. The safest fix is to replace WordPress core files with clean ones from WordPress.org.

unzip file

Unzip the files. Get a fresh copy from WordPress.org. If possible, use the same version your site is running. Extract the package on your computer so you can upload the files.

Upload files to filezilla

Upload fresh core files. Upload the new files to your server and overwrite the old ones, but do not replace the wp-content folder or the live wp-config.php file. If the error disappears, the core files were damaged.

If that does not work, the config file may also be part of the problem.

Rebuild wp-config.php if needed. Create a clean config file only after confirming your database credentials again. Then upload it and test the site.

MalCare security

Scan for malware. If the file damage was unexpected, run a proper security scan. A plugin like MalCare can help check whether the corruption came from malware.

If the files are clean and the error is still there, the database itself may need repair.

Repair database

phpMyAdmin Repair Table

A corrupted database is less common, but it can cause this error. If WordPress can reach the database server but cannot read the tables properly, repairing the database may bring the site back.

You can repair the database through your hosting panel or by using WordPress’s built-in repair mode in wp-config.php. If it does not help, the problem is more likely to be your credentials, files, or hosting.

Check your database server connection with the host

If your credentials are correct, plugins and themes are not the cause, the files are clean, and the database repair did not help, your host needs to check the database server.

This is especially common on shared hosting, where database servers can slow down or fail under load.

  • Contact support. Tell your host you are seeing Error Establishing a Database Connection and ask them to check the database server status. Have them confirm whether there is a MySQL issue, server overload, or recent maintenance affecting your account.
  • Check database privileges. Ask them to verify that your database user still has the correct access to your database.
  • Request logs if needed. If support says everything looks fine, ask them to check the actual error logs for failed database connections.

If your host confirms a server issue, the fix is on their side. If this happens often, it may be time to move to a host with better database stability and support.

Preventative measures

Once the site is back, a few simple habits can make this much less likely to happen again.

BlogVault backups new UI

Keep solid backups. A recent backup is the fastest way to recover from serious errors. BlogVault is useful here because backups are automated, off-site, and easy to restore even when wp-admin is down.

Edit-DB-info-in-wp-config-2

Be careful with wp-config.php. Most credential issues start with a small manual error. Check every value before saving changes.

Update WordPress New UI

Update carefully. Do not run big plugin or theme updates without a backup in place first. One bad update can take the site down.

MalCare security

Use security scanning. If files become corrupted, you want to know whether malware is involved. A security plugin can help catch that early.

Choose reliable hosting. Good hosting matters more than people think. If the database server is unstable, this error can keep coming back no matter what else you fix.

Parting thoughts

The Error Establishing a Database Connection message feels severe, but the fix is usually straightforward once you match the cause to the right step.

If you want the shortest path, restore a clean backup first. Then check wp-config.php, test plugins and themes, replace damaged core files, repair the database, and ask your host to inspect the database server if needed.

We know this error can feel urgent because it usually is. But you do not need to poke around blindly. Work through the steps in order, keep changes controlled, and you will usually get to the cause without making the problem worse.

FAQ

Why does it say Error Establishing a Database Connection on WordPress?

It says Error Establishing a Database Connection because WordPress cannot connect to your database. This usually happens because of bad database credentials, a hosting issue, a faulty plugin or theme, damaged files, or a corrupted database.

Why do I keep getting Error Establishing a Database Connection on WordPress?

You keep getting Error Establishing a Database Connection because the root cause is still there. Most often, that means wrong wp-config.php details, unstable hosting, or a plugin, theme, or file issue that was not fully fixed.

Can I fix Error Establishing a Database Connection without wp-admin?


Yes, you can fix Error Establishing a Database Connection without wp-admin. You can use FTP, SFTP, or your host’s File Manager to edit wp-config.php, disable plugins or themes, replace core files, and repair the database.

Will I lose my content if I see Error Establishing a Database Connection?


No, you usually will not lose your content just because you see Error Establishing a Database Connection. In most cases, the content is still in the database, and WordPress simply cannot reach it.

What should I check first for Error Establishing a Database Connection?

The first thing to check for Error Establishing a Database Connection is the database credentials in wp-config.php. If those are correct, move on to plugins, themes, damaged files, database repair, and then your host.

Tags:

You may also like


How do you update and backup your website?

Creating Backup and Updating website can be time consuming and error-prone. BlogVault will save you hours everyday while providing you complete peace of mind.

Updating Everything Manually?

But it’s too time consuming, complicated and stops you from achieving your full potential. You don’t want to put your business at risk with inefficient management.

Backup Your WordPress Site

Install the plugin on your website, let it sync and you’re done. Get automated, scheduled backups for your critical site data, and make sure your website never experiences downtime again.