How to fix Error Establishing a Database Connection in WordPress 100%

Is your website showing "Error Establishing a Database Connection" message? And even after reloading the web page, this error establishing a database connection WordPress message is visible on your website! So don't worry, you've come to the right place.

In this article, I will tell you how to fix WordPress Issues Establishing a Database Connection from a WordPress site.

  • Why does WordPress Error Establishing a Database Connection?
  • How to fix Error Establishing a Database Connection in WordPress?
    • 1. Repairing Database
    • 2. Check the WP-Config file
    • 3. Check Web Host (MySQL Server)
    • 4. Upload WordPress CMS

Why does WordPress Error Establishing a Database Connection?

When the WordPress website cannot make a connection with the database, then we see Error Establishing a Database Connection. And there are many reasons why this may happen, your Database login credentials may be incorrect or have been changed. Sometimes your database server is unresponsive or corrupted, even Error Establishing a Database Connection appears.

How to fix Error Establishing a Database Connection in WordPress

1. Repairing Database

First, we need to check whether our WordPress database is correct or not. If you try to access your wp-admin page and you find "One or more database tables are an unavailable error". So, we will need to repair the WordPress database error.

These are signs of database corruption but don't worry, you can easily repair your WordPress database with the WordPress inbuilt feature.

To fix the corrupted WordPress database, you must use your wp-config.php file, which contains your WordPress installation settings and configuration.

You need to add a code to your wp-config.php file and call it "That's all, stop editing! Add before the Happy blogging” line.

define ('WP_ALLOW_REPAIR', true).

Now go to this page - You will see one such screen,

You see two options "Repair Database and Repair and Optimize Database" in the above screenshot. From this you can select anyone but optimizing the WordPress database will take a lot of time.

If "Error Establishing a Database Connection" is not fixed from your site even after performing database repair, then continue reading this article for other solutions.

2. Check the WP-Config file

If you have changed your database name and password but have not updated this information in the wp-config file, then you may have to face "error signing a database connection".
So, check database information in your wp-config file.

If anyone of these values ​​is wrong, then WordPress will not be able to make a connection to the database. And will show you the error a database connection.

Many people say that by replacing localhost with IP, you can get rid of this database connection error problem.

define ('DB_HOST', '').

There is a separate IP for each web hosting.

3. Check Web Host (MySQL Server)

First, check the database name. To do this you have to login to cPanel. Then click phpMyAdmin in the Databases section.

Left-hand side, you will see the name of your database. Now compare this with the DB_NAME value of your wp-config.php file. If it matches, it's okay. If it does not match, you will need to update your wp-config.php file.

Whether or not you have selected the correct database - find the wp_options table for this and then click Browse. The URL of your WordPress site will appear in it. If it matches your site, then you have selected the correct database.

If your database name is already correct but your website is showing error message a database connection message, then check your Username and Password. To do this, create a file named testconnection.php in the root directory of your WordPress site and paste the code below.

$test = MySQL connect ('localhost', 'db_user', 'dB password').
if (! $test) {
die ('MySQL Error: '. MySQL Error ()).
echo 'Database connection is working properly!'.
MySQL close($testConnection).

replace db_user and dB password with db_user and dB password of your wp-config.php file.

After creating the file, search for this URL in your browser:

If you see "MySQL Error: Access denied", then your username or password is incorrect.

Note: Do not forget to delete/remove this file after testing.

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

For this, go to the MySQL database option in cPanel and create a new MySQL user.

Try to make username and password unique and strong so that they are not easily guessed. Then click on "Create User".

Then scroll down and add a new user to your database. On the next screen, check the All-Privileges box.

Now update your wp-config.php file with the new DB_USER and DB_PASSWORD values.

4. Upload WordPress CMS downloads a fresh copy of WordPress CMS from. To upload WordPress CMS files, use FTP instead of the file manager.

After downloading, extract the ZIP file and delete the wp-content folder and wp-config-sample.php file.

Then upload it to your WordPress cPanel via FTP. Your FTP client will show a pop-up for duplicate files, then you have to click on the option of Overwrite duplicate files.

One of these points will fix your WordPress error acknowledging a database connection.

If Error Establishing a Database Connection message show is still happening on your site, then contact your hosting company.

You can comment on any type of question or suggestion related to this article.