In this tutorial, we will show you how to troubleshoot the ‘Error Establishing a Database Connection’ error in WordPress websites.

If you are facing the ‘Error Establishing a Database Connection’ notice on your WordPress website then you should fix it ASAP because it’ll make your website inaccessible to all your users.

The most common reason for this error is when WordPress is unable to access or connect to the database. There are many things to check and debug. It can get a little complicated for new users to troubleshoot without proper guidance.

Reason for ‘Error Establishing a Database Connection in WordPress’?

The most common issue is when your wp-config.php file has some incorrect entries. It leads the WordPress to show this error. If the Database username, password or name is incorrect then it’ll show this error.

There can be some other reasons like MySQL server is down or the database is corrupted etc, but it happens in some rare cases.

CMS like WordPress uses database to store everything including your content and site data. If the connection fails with database then the Website may throw this error.

How to Fix ‘Error Establishing a Database Connection in WordPress’

In the most cases we noticed that it happens because of incorrect credentials of database in Wp-config.php file. After migration, incase if you forgot to update the database name, user and password in Wp-config.php file then you are likely to get this error.

Fixing Database Credentials in wp-config.php file.

Step 1. Open wp-config.php file from cPanel or any file manager.

Step 2. Look for lines:

Once you have located this, simply verify that they are correct, many times there are blank spaces in the beginning or end when you copy paste something. Incase you don’t remember just follow the next steps to find out.

Step 3. In cPanel open MySQL Databases.

Step 4. Now check the privileged user for the database and change it’s password.

Once you have changed the password, mention it in the Wp-config.php file if needed, now check if your website is giving database error or not. In most of the cases it’ll be solved.

If you are still facing issues, keep reading, for next steps.

Repair WordPress Database

If you are getting this error in some parts like wp-admin page or anything like that, then you need to repair your WordPress database.

It is simple, you just have to add a single line in the wp-config.php file.

define(‘WP_ALLOW_REPAIR’, true);

Add this line before “That’s all, stop editing! Happy blogging”

After saving the file you can simply open the maintenance url.

It’ll be like https://domain.com/wp-admin/maint/repair.php

Just click on Repaid database and have a cup of coffee as it may take few minutes.

Bro Tip: This page can be accessed without admin access, so make sure you remove that line immediately after the process is done.

Check if your Database server is down

Sometimes due to heavy load, SQL server gets down. Incase you are on shared hosting, there’s nothing much you can do apart from contacting the support but you can verify if the database server is actually down or not.

Open the dashboard of your hosting provider and look for phpMyAdmin.

Now use the credentials that you mentioned in the wp-config.php file in the first step.

If you are able to see your tables then the database server is up, or if you get any error while checking your tables, contact support.

Restart MySQL / Web Server

In case you are using Dedicated servers or VPS or Cloud instances, you can simply restart MySQL server or the whole Web server.

This may fix some temporary glitches you are getting on your website.

Contact Hosting Support for Help

If you are using any managed web hosting like Host It Bro, you can simply open a support ticket or contact on live chat with your registered email id to get it solved. You can contact your hosting provider via your preferred method if none of the above mentioned steps works for you.

Conclusion

So, this is how you can get rid of “Error Establishing a Database Connection in WordPress”. Let us know if you have any other methods to solve it in the comment section below.

Previous ArticleNext Article

Leave a Reply

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