How to fix “Error Establishing A Database Connection” in WordPress

How to fix "Error Establishing A Database Connection" in WordPress?
  • Hello Friends today I will WordPress Error establishing a database connection setting a database connection message is a frustrating wordpress error in which an error opens up in front of your site, just like the screenshot shown below:

Error Establishing A Database Connection”

If you are reading this post now, you might still be facing this error, if not, you are lucky.

If you are not getting this message right now, then knowing about fixing this thing will be important for you as a user of WordPress.

In this post, you will learn about three things:

What does our website error mean? Some of the most common reasons that cause this error. How to fix this error in WordPress.

Contents – [Contents hide]

How to fix Error in WordPress?

PotentialFix 1: Check if you still have.

Potential Fix 2: Check your database’s login credentials.

Potential Fix 3: Re-upload WordPress core files.

Potential Fix 4: Talk to your host. Last thoughts.

If you do not know how WordPress works, know that the WordPress website has two parts:

Your files: There is a software in WordPress, your themes media uploads etc. Your database: This is the place where the actual content and pages of your posts are stored. (As well as other important information too)

When a visitor lands on your website, PHP files go to your database and find out exactly what information is displayed.

If PHP files do not have a working connection with the database then your WordPress site will not be able to show the information that it should show. For this reason, you get a message of “Error Establishing A Database Connection”.

What are the reasons?

If you encounter this error, then there are many reasons for this.

In most cases, these can be:

A corrupted database in your wp-config.php file incorrect configuration of the database. Worst core files are corrupted. Problems with your web hosts.

Because you can never be sure that what exactly is causing an error, then you have to take a diagnostic approach in a way.

In this you have to alternatively check and fix the problem by following a series.

Let’s know how you would do this:

How to fix website problem?

Potential Fix 1: Check if you can still access your WordPress dashboard or not.

If you see this message in the front end of your site, the first thing you need to check is whether you are able to access your WordPress dashboard or not.

If you get the same error even if you wp-admin access, then by skipping this step, follow the next step.

If you get a different message, such as “Database may need to repair”, then continue with this section to repair your WordPress database.

Step 1: On the repair utility in wp-config.php file.

To get started, you will need to edit your site’s wp-config.php file, you can do it in two ways:

By connecting your site with an FTP client. (Filezilla is a great FTP program) by using cPanel’s built-in file manager.

Error Establishing A Database Connection”

Your wp-config.php file will be in the root folder of your WordPress site. This will be the same folder in which you will also find wp-admin and wp-content folders.

Error Establishing A Database Connection”

Once you open your wp-config.php file to edit, add this line of code to the bottom of your file:

define (‘WP_ALLOW_REPAIR’, true);

Do not forget to click Save to save the changes before continuing.

Step 2: Running Automatic Database Repair Utility.

Once you add code snippet, you can access the WordPress database repair tool by visiting the following URL:

On this page, you will have to click on the Repair Database button.


Once this tool completes the repair of your database, your site should hopefully work. If such a thing works, then you just have to remove it from the wp-config.php file and delete the code that you just added.

If this does not work for your site then move on to the next step.

Potential Fix 2: Check your database’s login credentials.

If your database is not corrupted, then the next thing that you need to check is whether your database’s login credentials are correct or not.

The credentials of your database are also defined in the wp-config.php file.

fix error establishing a database connection wordpress

If this information does not match your actual database credentials that you created in your host dashboard, WordPress will not be able to access your database.

You can use the mysql_connect () function to check that your database credentials are working or not.

Using a text editor like Notepad, create a file whose name, databsecheck.php.

After that add this code snippet to the file:

<? php
$ link = mysql_connect (‘localhost’, ‘mysql_user’, ‘mysql_password’);
if (! $ link) {
die (‘Could not connect:’. mysql_error ());
echo ‘Connected successfully’;
mysql_close ($ link);

Do not forget to replace “mysql_user” and “mysql_password” with your actual username and password which is used in your wp-config.php file.

Then upload this file to cPanel or FTP on your website and then go to the URL below:

If you get a message of “Connected Successfully”, your database credentials are working, you can go to the next step, by skipping it.

But if you get any such message, as shown below, then there is a problem with your database credentials.

The easiest way to fix this problem is to create new credentials for your database.

Step 1: Go to MySQL databases in cpanel.

I assume that your host uses cPanel, you can go to MySQL Databases and create a new database user.

mysql database

Scroll down to MySQL users, and find the box with Add New User.

A new:



Enter it.

mysql users

Remember this details, because you will need them now.

Step 3: Add a new user to the database.

Once you have created a new user, you must go to Add a User to a Database option and add a new user to your WordPress site’s database.

Add user to a database

Do not forget to give ALL PRIVILEGES to the user on the next screen.

fix error establishing a database connection wordpress

Step 4: Update wp-config.php file with the new database user.

To complete this task, you will need to open the wp-config.php file again and update the DB_USER and DB_PASSWORD fields to the new user.

Once you save these changes, your site should hopefully be working again.

Potential Fix 3: Re-upload WordPress core files

If any of the methods mentioned above do not fix this error, then your WordPress core files may also be corrupted, in such a case you have to re-upload them.

For this purpose, I recommend you to use FTP program instead of File Manager.

Note: Make sure you take a complete backup of your site before doing all this. In this regard, you read our article: How to Get Full Backup of Your WordPress Site?

Download WordPress latest version from

fix error establishing a database connection wordpress

Once the download is finished, extract the ZIP file and delete it:

All wp-content folder.

wp-config-sample.php file

fix error establishing a database connection wordpress

After this, upload all the remaining files via FTP, on your WordPress site. Your FTP program will prompt you to duplicate files. When this happens, do not forget to select the option of Overwrite duplicate files.

Potential Fix 4: Talk with your host.

If above, any solution does not work, then you are dealing with a hosting issue.

Some hosting related problems that may occur in this context:

Your database server is down: Some hosts use a separate server for databases, which means that your database may be down, even when the regular server is working.

Your database quota has been completed: Some shared hosts impose limits on your database usage. If your site crosses limits, this is the reason why your database goes down.

You have to talk to your host team to solve this problem.

final thoughts

To this point, the error of should be removed from your front and your site should be working again.

Still there may be some issues that can cause this error. These issues are usually unique issues of your site and for this reason it is difficult to diagnose through such a post.

If you have also tried all of the solutions mentioned above and you have talked to your host, but you still have an error in “Error Establishing A Database Connection”, you should try to solve this problem further. You must hire a WordPress developer for

You can also comment below! Maybe we can solve your problem together!

You May Also Like

About the Author: Gaurav Kumar


  1. DirectX 12 continues to be a brand-new technology – and in a few ways it is still – however in reality we’ve now been discussing the images API for the better part of half of a 10 years. Microsoft first declared the then-next era design API to much fanfare again at GDC 2014, with the original iteration shipping within Home windows 10 a time later. For a variety of reasons DirectX 12 adoption continues to be in its start – software dev cycles are long and Operating-system adoption cycles are much longer still – but with their low-level images API firmly set up, Microsoft’s DirectX clubs already are hard at the job on another generation of design technology.

Leave a Reply

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