WordPress is an excellent platform for blogging, and it’s the most used content management system. Most of the time WordPress run’s without errors, but sometime it shows error messages. Error Establishing a Database Connection is the most common WordPress error; you can solve this error easily by following this tutorial on how to fix Error Establishing a Database Connection in WordPress

When “Error Establishing a Database Connection” message is shown in the screen when you try to access your website, it means your website is down and you are losing your traffic at that time. This error mostly happens when; you make any changes to your database. I recommend you to backup your database before changing, so that you can use the backup copy if anything messes up.

Error Establishing a Database Connection

Error Establishing a Database Connection

This is one of the most common WordPress errors, which happen because WordPress can’t establish a connection with your database. It could be because of any wrong changes made in the database or it may be because that your database server not responding when it is called. This error will happen mostly due to some kind of sever error.

Every thing in your website is stored in Mysql database and PHP codes are used to get that stored in Mysql database, the “Error Establishing a Database Connection” happen when for some reason PHP codes cant assess Mysql database. As I told you it can be error due to sever not responding or any changing made in database. Now let’s see how to fix “Error Establishing a Database Connection”

How to Fix the Error Establishing a Database Connection in WordPress

You just need to follow the below steps to fix “error establishing a database connection” in WordPress. There are three methods that will help you to solve the error establishing a database connection. Any one of the following methods can fix this error.

Determine the Error

First visit yourdomain.com/wp-admin and see whether there is some other warning message in that page like; “one or more database tables are unavailable. The database must be repaired”, this means that you should repair your database.

For repairing the database, first login to your cPanel and then click on file manager and then from that find wp-config.php and add the below codes to that file at the bottom.

Define(‘WP_ALLOW_REPAIR’, true);

After you have added this simple code then, you need to go to setting, visit yourdomain.com/wp-admin/maint/repair.php

You should remember that this page can be visited by anyone without login, so you need to remove this code from wp-config.php after you fix the error. If this doesn’t solve the error then follow another step,

Check your Database login Credentials in wp-config

First open Wp-config.php and then, find whether you have the following codes

 Define(‘DB_NAME’,’database number’);Define(‘DB_USER’,’databaseusername’);Define(DB_PASSWORD’,’database- password’);Define(‘DB_HOST’,’localhost’);

Note: DB_HOST value can vary it depends on your host, Most popular host have ‘localhost’ as the value

If every thing is same then, wp-config file is not having any error, then the problem is on your server.

Checking your server

If the above two are not the reason for the error establishing a database connection then the only chance is that your web hosting site is not capable to handle the load, this happen mostly when you are hosted in the shared hosting plan. You need to contact the customer care for asking why your server is not responding to the call and end up in the error establishing a database connection.

In my opinion no popular host server like, BlueHost, Hostgator provide such errors. These are the three possible ways to solve the error establishing a database connection.

Advertisements