How to Fix Error Establishing a Database Connection in Wordpress Website

How to Fix Error Establishing a Database Connection in WordPress Website

Is your website show “Error Establishing a Database Connection” message? And even after reloading the web page, this Database Error Connection message is visible on your website! So don’t worry, you’ve come to right place.

How to Fix Error Establishing a Database Connection in WordPress Website

In this article I will tell you fix Error Establishing a Database Connection from WordPress site.

Why WordPress Error Establishing a Database Connection?

WordPress site 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.

Error Establishing a Database Connection Fix in WordPress site

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 unavailable error”. So we will need to repaired the wordpress database error.

These are signs of database corruption, but don’t worry, you can easily repaired 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 setting and configuration.

You will need to add this code to your wp-config.php file and call it “We’re all, stop editing! Add before the Happy blogging ”line.

define (‘WP_ALLOW_REPAIR’, true);

Now go to this page – www.yourwebsite.com/wp-admin/maint/repair.php. You will see one such screen,

You see two option “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 any one of these values ​​is wrong, then WordPress will not be able to make a connection to the database. And will show you the error error a database connection.

>>> How to Fix White Screen of Death in WordPress Website

>>> How to fix 500 Internal Server Error in wordpress website

>>> How to fix broken links in wordpress without plugin

>>> How to create backlinks for my website

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

define (‘DB_HOST’, ‘127.0.0.1:8889’);

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 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.

<? php

$ 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: yoursite.com/testconnection.php

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 databases 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

Download a fresh copy of the WordPress CMS from WordPress.org. To upload wordpress CMS files use FTP instead of file manager

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

Then upload in your WordPress cPanel Using 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 for any type of question or suggestion related to this article.

Leave a Comment

error: Content is protected !!