Learn How To Fix Error Establishing A Database Connection In Your WordPress Website


Have you ever encountered an error called “Error Establishing A Database Connection”? If yes then TheWebsiteDev is here to help you and fix “Error Establishing A Database Connection” issues.

If you’re a WP website owner, this error can really make a day sorry for you. Whether you talk about basic website design or WordPress site elements, there will be nothing but just a text stating “Error Establishing A Database Connection.”

Well, calm down, sit back and relax. There is nothing to worry about. Today we will teach you five best steps/approaches to fix “Error Establishing A Database Connection.” But before we explore those approaches, it’s good to get more familiar with the problem.

“Error Establishing A Database Connection”: The Problem

The error itself explains the problem, that’s it’s a kind of error occurred because of database connection failure. But what does that exactly mean? Here it is…

You must be knowing that WordPress works with two major technology pieces to offer users it’s excellent functionalities and abilities. These two technology pieces are called PHP and MySQL.

PHP is nothing but a programming language. The core files of WordPress are written in PHP language. On the other hand, MySQL is the database technology used by WordPress to store and access all your website elements and contents. The Statement is valid for all your website pages, blog posts, and all other minor and major elements of contents that you put on your website. In short, the MySQL database is the place where all your website information is kept securely.

So, WordPress uses both this mentioned programming language and the database technology to work as it should. WordPress uses commands by PHP to establish a connection with the MySQL database to get all the required information and then display everything on the screen.

Now, that’s where the error comes into the picture. If due to any reason, WP fails to access information from the MySQL database using commands by PHP, the error takes place. 

Here we have listed some common reasons that usually results in “Error Establishing A Database Connection.” Have a look below to get familiar with them.

✔️ Incorrect Login Credentials

You must be knowing that WP requires some specifically defined username and password to access the database. If there will be any change in those login credentials due to any reason, the WP will not be able to fetch any detail or data from the database. As a result, it displays nothing but only text on display as “Error Establishing A Database Connection.”

✔️ Corrupted Core WP Files

The core WordPress files can easily get corrupted due to failed updates. Failed plugin updates, theme updates are some common cases.

✔️Corrupted WP Database

Hacker attacks, theme failure, etc. results in the corrupted database, and thus the error takes place.

✔️Database Server Failure

A web server is something that stores website files. So, whenever the web server fails or goes down, the error is usually encountered.

✔️Massive Traffic

Who doesn’t want to have enormous traffic for their website? Well, massive spike in traffic can also make website database unresponsive. Thus, enormous traffic is another reason you may encounter this error.

So. that’s the list of common reasons. Let’s now proceed to explore some best approaches to fix this error.

Top 5 Step Approach To Fix “Error Establishing A Database Connection”

Step 1: Contact Your Web Host Service Provider

Learn How To Fix Error Establishing A Database Connection In Your WordPress Website

The fault can also be on your host’s end, and thus it’s good to get in touch with your service provider.

Most of the quality host providers offer immediate support through the live chat system. So, contact your web host provider through live chat feature and ask them about the error you’re encountering. Also, ask them if this error is due to server issues.

Generally, they find out the cause and let their customer know what precisely the issue is, and even they can fix it for you.

Above all, they will let you know if there’s any suspicious activity on the server and whether the database is active and secured or not.

In case, if they tell you that there is no fault from their end, that’s server is operational and there is no spike in traffic too, just proceed with the step 2 as mentioned below.

Step 2: Ensure That Theme And Plugin Files Are Not Corrupted

WP files generally get corrupted due to several unforeseen events.

For example, you might have updated your website theme or a plugin, and the whole thing might have collapsed, maybe you have manually edited some WP core files, etc.

Well, if you haven’t done anything as mentioned above, this step is not for you. If yes then here is how you can fix Error Establishing A Database connection in your WordPress website.

#1 First of all establish a connection with your host with the help of FTP.

There are many tools available for this purpose, however here we recommend using FileZilla. To connect with the host, you will need login username and the password. If you have no idea what’s your login credentials, just go to your email account and check for the initial emails that your web host sent you when you signed up for the first time. Also, you can again use the live chat feature to ask the customer support for the login credentials.

Once you get the details, connect to the web servers using those credentials and access root folders of the WordPress. Once you access the root folder, you find sub-folders named as wp-admin, wp-content, etc.

Fix Error Establishing A Database Connection In Your WordPress Website

#2 Now just go to the “wp-content” subfolder and rename the “plugin” folder name. You can rename the subfolder to anything but not as “plugins.”

error establishing a database connection GoDaddy

Now check if the “Error Establishing A Database Connection” is fixed now. If not then you are sure now that plugin is the main culprit behind this error. Now get back to the FTP and rename the folder back to its actual name, that’s “plugins.” Now open this folder and rename the name of individual plugin folders available there.

how to fix error establishing a database connection

Also, keep checking your website after renaming the folder to check when the error is triggered or vanishes. In the end, you will find one specific plugin which will be the actual troublemaker. You can just delete that and go online and check if the issue is resolved.

If you still encounter the same error, follow the same renaming steps with “themes” folder. If none of both renaming approaches fix the issues, rename them back to their actual folder name as some other elements of your website have caused the problem.

Step 3: Ensure That  Database Is Not Corrupted

The database of WP is quite complex, and there are so many tiny elements that need to be active to ensure the proper functioning of a website. Generally, people encounter error establishing a database connection in their WordPress website when something goes wrong with database elements.

  • Start with checking the dashboard of your WordPress website (yourwebsitename.com/wp-admin)

If you still see error establishing a database connection, just skip this step.

  • If you see something else as shown below pay attention to the suggestions provided by WordPress.

error establishing a database connection xampp

You may also see a message stating that “One Or More Database Tables Are Missing.” Well, this message means that it’s you who need to repair the WP database.

Well, it’s not that complex to do. All you need to do is connect again with the FTP and access WP root and download a file called “wp-config.php” to your laptop or PC. Once downloaded, edit the file in notepad and add an extra line, as mentioned below, at the end.

define(‘WP_ALLOW_REPAIR’, true);

Once done upload this file back to your WordPress website to allow overwriting the older version.

Now Go to yourwebsitename.com/wp-admin/maintenance/repair.php. Below is something that you would see after accessing the mentioned link.

error establishing a database connection chrome

Click any of the buttons available. Once the automatic repair is done, check your website if the error is resolved. If not then you need to proceed with the next step.

Step 4: Check Credentials Of WP Database Connection

As said at the beginning of this post, WordPress requires a username and password to access the database. Those access credentials usually never change on their own. However, you can encounter a few bugs or issues after making any changes to your website files, hosting services, etc. In short, even though the credentials are not supposed to change, they change sometimes.  And “error establishing a database connection” is the result of lousy access credentials.

To fix this error. You need to work on the wp-config.php file as shown below.

define(DB_NAME’, “define_db’);

define(DB_USER’, ‘define_username’);

define(DB_PASSWORD’, ‘define_password’);

define(DB_HOST’, ‘localhost’);

These holds almost every details that WP requires to access the database. If any of these details will go wrong, the WordPress database connection failure will happen.

Get these four details from wp-config.php. Just copy these lines and paste into the live chat support and ask your web host if details are correct. The representative will let you know whether the details are exact or need any modifications. If there will be anything wrong or changed, they will let you know the correct details.

Once they provide you with the new details, all you need to do is copy the further details and paste them into the wp-config.php where that old file was kept. That’s it. Now re-upload this new file with the help of  HTP and check your website.

error establishing a database connection cpanel

If still, you see the same error establishing a database connection, proceed with the final step as mentioned below.

Step 5: Restore Default WP Files

As said at the beginning of this post, there are so many reasons that may result in corrupted WP core files.  Hackers attack, file modifications, etc. are some common reason behind the issue. Whatever the reason is, you can always restore native/default WordPress core files. All you need to do is, download the clean WordPress version from WordPress.org website and copy and paste that to the one you’re having actively.

Just visit this page and download the latest WP package. Once downloaded, unpack and browse the unpacked archive and delete the folder called “wp-content.”

Once done, connect your website using FTP again, go to the WordPress root section, upload new WP files there and overwrite all those existing files.

So once the uploading is done, go back to your webpage and check if error establishing a database connection is fixed.

This one is the last approach that we think can help you fix error establishing a database connection. If none of the above steps work for you, you will have only option to contact your web host. Use the live chat support feature and tell them everything that you did and the results. Ask them for the help, and they will surely find out the troublemaker and fix the issue for you. With all these steps and approaches you have done everything that possibly you can do to fix error establishing a database connection. Now it’s your web host turn to take the command and fix the issue. After all, you’re paying them for their services.

Two Ways To Avoid “error establishing a database connection” In Future

There are no 100% full proof approaches to protect your website again errors, especially “ error establishing a database connection” type of bugs. However, there are two key elements that you must take care of to ensure proper functioning of your website.

1 Always Choose Quality Web Host Service Providers

Always choose hosts who have a WordPress compatible platform. With a quality host, you can expect quality support from the knowledgeable support team. Also, they will be taking care of efficiency and functioning of your website. So, it’s really good to opt always quality web host.

2 Always Have A Backup

You can just install plugins for these purposes like UpdraftPlus which works automatically without any manual effort. You should always have a valid backup for your WordPress website for critical scenarios.


So, that’s how you can fix error establishing a database connection. Hope you enjoyed reading this post. Also, read “Best WordPress Job Board Plugins” and “Best News-Editorial WordPress Themes For Your Website.” Let us know in the comment section if you find any of the mentioned steps problematic. Also, do follow us to get more such troubleshooting and web development stuff. So, that’s it for now and all the best. Also, let us know if this post helps you to troubleshoot the error.

People reacted to this story.
Show comments Hide comments
Comments to: Fix “Error Establishing A Database Connection” In Your WordPress Website
  • April 9, 2019

    Thanks for the guide, just getting started with WordPress and had this issue.

    • April 9, 2019

      Hope this guide has helped you. Thank you!

Write a response

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

Attach images - Only PNG, JPG, JPEG and GIF are supported.

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Join TheWebsiteDev