Choose another country or region to see content specific to your location and shop online.
USA

Why am I getting the “error establishing a database connection” on my WordPress website?

Picture of William Bacchus
William Bacchus

Published: May 7, 2024

Last updated: May 7, 2024

Table of Contents

Error Establishing a Database Connection

The “error establishing a database connection” is one of the most frequent issues WordPress users face. This error, often associated with the white screen of death (WSOD), indicates that your website has lost its link to the WordPress database, causing your entire site to go offline.

It’s critical to fix this error as soon as possible because it can disrupt your sales, visitor traffic, and analytics. However, there’s no need to stress. Today, we’ll explore the typical causes of this error and provide some straightforward solutions to get your website back up and running quickly.

What is the Error establishing a database connection?

WordPress is built using PHP (like index.php and sidebar.php) and MySQL. PHP handles all the functional aspects of your WordPress site—such as posting comments and retrieving posts and pages—while MySQL manages data storage.

For example, when you type your website’s URL into your browser and press Enter, PHP starts working by fetching and displaying the homepage content (index.php) from your MySQL database. However, images, videos, and other media are stored in the wp-content folder, which PHP retrieves separately.

Your MySQL database contains all the essential information PHP requires to generate your site. If PHP is unable to access your MySQL database for any reason, you encounter the dreaded “error establishing database connection” message. This message indicates that PHP couldn’t find the data it needed to construct your WordPress site.

Why is the Error establishing a database connection appearing on my website?

Why does this happen? Below are a few common reasons. Don’t worry, we’ll explore each of them in detail so you can understand how to resolve the issue. Typically, you can fix this error in less than 15 minutes.

Invalid Database Login details

Your WordPress site relies on unique login information to establish a connection with its MySQL database.

Corrupted database connection

Given the dynamic nature of themes, plugins, and user activities—such as frequent deletions and installations—databases can sometimes become corrupted. This could result from a missing or damaged table, or perhaps some crucial information was accidentally deleted, leading to the database connection error.

WordPress Installation has corrupted files

Sometimes this can happen because of a hack or other cyber crime.

Issues With The Database Server

On the web host’s side, several issues might arise, such as overloading the database due to a sudden spike in traffic or becoming unresponsive because of too many concurrent database connections. This situation is common with shared hosting, where multiple users share the same server resources.

Traffic Spike

Depending on your web hosting provider, your server might struggle with a high number of concurrent database connections. A surge in traffic can cause temporary issues with the database.

Now you know what causes the error, let’s take a look at how you can resolve it.

How to fix the “Error Establishing a Database Connection” on your WordPress website

Before you start troubleshooting any issues, it’s crucial to back up your WordPress site. The steps below involve making changes to your database to restore the database connection, and you definitely don’t want to risk causing more problems. Regardless of your technical expertise, it’s best to always create a backup before attempting any fixes on your WordPress site.

To back up your WordPress files and database, you can use popular plugins like VaultPress or WP Time Capsule.

If you’re an Elite customer, you can use our built-in backup feature. Simply login to your account, find your WordPress hosting under “My Products”, go to the “Backups” section, and click “Backup Now”. Here you’ll also be able to view all your previous backups too.

Let’s start by determining whether the error is caused by a corrupted database. To do this, we need to check if the back-end is also affected.

Go to yoursite.com/wp-admin/. Just remember to replace yoursite.com with your actual domain name.

If you get the “EEDC” error when loading both the front-end (yoursite.com) and the back-end (yoursite.com/wp-admin/), your database is likely fine, so you can skip ahead to checking if your wp-config.php file has the correct login credentials.

However, if you encounter the message “One or more database tables are unavailable…” or anything other than the “EEDC” error, your database connection might be corrupted and needs to be repaired.

Don’t worry; repairing your WordPress database is quite straightforward. It can be done in three simple steps. First, locate your wp-config.php file, which is in the root directory of your WordPress installation. The root directory is the folder where you have installed WordPress.

You can normally locate this folder inside the default home folder or “public_html”. Login to your cPanel, and navigate to File Manager.

file manager for fixing the database connection

Then head to the WordPress root folder:

From here, locating your wp-config.php file is going to be easy:

After you’ve located the wp-config.php file, open it for editing. You can usually do this by right-clicking the file and selecting “Edit” or “Open with Code Editor.” If you’re using a hosting control panel like cPanel, you might find an option to open the file with a built-in code editor. Make sure you’re in editing mode before proceeding with any changes.

This opens your wp-config.php in a new tab. Add the below code at the bottom:

define ( 'WP_ALLOW_REPAIR' , true);

Ensure that you save your changes.

The code snippet provided lets you repair your WordPress database without the need to manually access phpMyAdmin, which can be tricky depending on your level of expertise.

For the second step, navigate to yoursite.com/wp-admin/maint/repair.php in your web browser. This should bring up the following screen:

For the third step, simply choose either “Repair Database” or “Repair and Optimize Database” and let WordPress take care of the rest.

Important: After your database has been repaired, be sure to delete the code you added to the wp-config.php file. Leaving it in place could give hackers access to your database, allowing them to cause serious damage.

If repairing your database resolves the issue, congratulations! You can celebrate your success. However, if the error persists after repairing the database, it might be due to incorrect login credentials, corrupted WordPress files, or an unresponsive database server.

It is worth checking your database login credentials and making sure they are correct, or even contacting your hosting provider to see if there is an issue out of your hands.

Conclusion

As you can see, there are more than one resolutions to the “error establishing a database connection” in WordPress. The most common cause is incorrect credentials in the wp-config.php file, so that’s usually the first thing to check. Website downtime is something you want to avoid, so it’s important to address this error quickly.

Ideally, one of the steps mentioned earlier has helped you get your site back online. If things still aren’t working, remember that you can always restore your site from a backup.

Sign up for free news, tips & offers

Your email is safe with us, we don't spam.

Picture of William Bacchus
William Bacchus
Will joined the Elite team in 2021. He has a background in content writing as well as a keen interest in media journalism. His interests include taijutsu and a immense passion for film and television. He aims to inform as many people as he possibly can about the vast and often confusing nature of web design!

Leave a Reply

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

Reseller login

If you’re a reseller, use the button below to sign in. (your reseller account is separate to your regular account)

New customer

New to ELITEWEB.Co? Create an account to get started today.

Registered users

Have an account? Sign in now.

Sign up to our newsletter for the latest news + a Free WordPress Guide

NEWSLETTER