How To Fix “Error Establishing A Database Connection” in WordPress

When you are visiting any WordPress related blog then you may experience the error in establishing the database connection in WordPress.

You will have the information about the three things:

  • Meaning of “error in establishing the database connection in WordPress.
  • Reasons why all these messages appear.
  • And fixing of this error in WordPress.

Error Establishing A Database Connection

 The working of WordPress is based on two essential parts:

  • Your files- it includes the WordPress software, themes, plugins, and all your media uploads.
  • Your database: the place where your all data of your post and pages are actually stored including the precious information.

Fix error establishing a database connection in wordpress

The reason for the error established:

There can be many reasons behind this message. But most of the time it is done by the corrupt database. It also occurs when there will be corrupt WordPress core files and having problems with your web host. The major reason behind this problem is the incorrect database configuration details in your wp-config.php file.

You can identify these problems and perform a test to isolate the problem.

Fixing of the Error Establishing A Database Connection:

Potential fix 1: ( make sure and check if you can still access the WordPress dashboard)

The first thing to do when this message appears on the front end of your site then, check it down that you are getting the same error when you are trying to access your wp-admin dashboard. If the problem exists with that dashboard also then you can skip to the next step. You have done the eliminating of the problem as a potential cause,

If the message is not same as the above and something like this written in screen “ the database need to repair” then you can go with steps given below.

WordPress dashboard - Fix wordpress database error

Step 1:

Just turn on the repair utility in the wp-conf.php file:

Before starting this process, we need to edit the wp-config,php file for your site. There is another step to do that:

  • The connection of your site with the FTP.
  • And the use of cPanel’s built-in File manager tool.

The same address as the folder contains wp-admin and wp-content is where your wp-config.php file is actually located.

You will have to add the shortcode to the editing your wp-config.php.

Define( ‘WP_ALLOW_REPAIR’, true );

Before going further, save the changes you have made till now.

Quick links:

Step 2:

The running of the automatic database repair utility

After the adding of the code snippet given above you can now access the WordPress database repair tool on.

YOURDOMAIN.com/wp-admin/maint/repair.php

Just click on the repair database to start the tool. After the tool fixes all the problems, your site will be completely working again. Then you should return to your wp-config.php file and remove the code you have just added to the repair utility.

Potential Fix 2: (Go and check your database login credentials)

Before going on this step ensure that your database is not corrupted and also check that your database login credentials are working.

WordPress log in

If somehow these data is not matching with the database credentials which you have created via your dashboard. Due to that WordPress will not be able to access your database. Just use notepad and write down this code.

</php

$link = mysql_connect(‘localhost’, ‘mysql_user’, ‘mysql_password’);

If (!$link) {

die(‘Could not connect: ‘ . mysql_error());

}

Echo (‘Connected successfully”;

Mysql_close($link);

?>

Just replace MySQL with mysql_password with the actual username and password. Then you have to upload that file to your website with the help of cPanel or by FTP.

YOURDOMAIN.com/databasecheck.php.

If “connected successfully” appears then your database credentials are working and just go to the next step.

But you have got a message saying access denied then there must be a problem with the database credentials.

Just go and create new database credentials for your WordPress site.

1. Go to my SQL database in cPanel:

Just keep in mind that your host is using the cPanel, just go and create the MySQL Database option in the dashboard.

2. Create a new user:

Just go to the MySQL and find the box to Add a New User, enter new username and password.

3. Just add a new user to the database:

After creating a new user, you can now go to the Add a User to a database option and add the user to your WordPress site database.

Use ALL PRIVILEGES on the next line.

4. Go and update the wp-congig.php file with the new database user:

Just to finish this process you have to go back to your site wp-config.php file and just update the DB_USER and the DB_PASSWORD.

Potential Fix 3 (Reupload the core WordPress files) :

If somehow all the above methods are not working to fix it then you should go with this one.

Just upload a fresh copy of  WordPress to your site. It will not affect your existing content, plugins, and themes.

Install wordpress - Error establishing database connection

Just update the version of WordPress by going to wordpess.org.

All you need to do now is to extract the zip file and delete the wp-content folder along with the wp-config-sample.php file.

Also, read:

Upload the remaining file via FTP on WordPress. Just overwrite the duplicate files.

This will make none of your core files are corrupt, this will fix all the issue.

Potential Fix 4 (Try to speak with your host):

If somehow all the methods are failed and you may deal with some issues. Some of the hosting potential problems are:

  • Your database server is  down
  • Your database has somehow met its quota

Finally, if you are having such problems then you should go to the host customers care.

Now you are able to fix the error establishing a database connection message. Do share it on all the social media platforms. Let me know if there is some problem.

Recommended Hosting

Bluehost
Bluehost logo new
Support
Features
Money-back Guarantee
Migration
Security Issue

Pros

  • Free Domain
  • Unlimited Bandwidth
  • Money-back Guarantee

Cons

  • Limited CPU Usage
  • Customer support in Bluehost is pretty slow
  • Bluehost only has one set of DNS:
About Shubham Singh

A soul in search of peace, joy, success, eternal sunshine is wandering inside a person so called me. A writer, an observer, a man in making. What you have today is your PRESENT live it, love it, enjoy it, make moments and manifest because this will create your future. Your today's hard work and dedication will definitely proclaim your success tomorrow. You can get in touch with me via my email for content writing projects : [email protected]

2 Comments

  1. Vikas Kumar Katariya

    Nice Artical ….. Helpful For Me … Thanks Again

    Reply  
  2. Prabhu Ganesh

    Hi
    This is prabhu. i’m a web developer and i work with wordpress. This article about How To Fix “Error Establishing A Database Connection” in WordPress is really good. as a wordpress users everyone would have faced this issue atleast once. as a beginner it will be a nightmare. But this article is really good to know how to fix this issue. Thanku so much

    Reply  

Leave a Reply

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