Fix the Error Establishing a Database Connection in WordPress Site

If you’ve got been surfing the internet for a whereas, you have at least seen this error some times. Error Establishing a Database Connection is one of these curses that could be caused by many reasons. As a WordPress beginner, this could be awfully frustrating specially when it happened on its own without you changing something. We tend to ran into this issue yesterday on our own site. It took a little over twenty minutes to detect and fix the matter. Whereas doing the research to find potential causes, we tend to realized that there was no smart article that covered everything. In this article, we have a tendency to can show you the way to fix the error establishing a database connection in WordPress by compiling an inventory of solutions all in one place.

Please Note : Before do anything Do Backup you site First ..

Check this : Easy Way to Backup and Restore You Theme Options in WordPress

If you don’t like to read the whole article then please watch this video guide ….

Why do you get this error?

In a sort ..this is happen when database could not connect with server properly ..It happen many reason It may be that your database login credentials are wrong or have been changed. It might be that your database server is unresponsive. It may be that your database has been corrupted. In our expertise, majority of the times this error happens because of some type of server error but there may be alternative factors as well. Lets have a look at how to travel regarding troubleshooting this problem.

Is the problem occur for /wp-admin/ as well?

First factor you must do is to create sure that you are obtaining the identical error on each the front-end of the site, and the back-end of the location (wp-admin). If the error message is the identical on each pages “Error establishing a database connection”, then proceed onto the next step. If you are obtaining a completely different error on the wp-admin for example something like “One or more database tables are unavailable. The database might would like to be repaired”, then you wish to repair your database.

You can do this by adding the following line in your wp-config.php file. Add it simply before ‘That’s all, stop editing! Happy blogging’ line wp-config.php.

define('WP_ALLOW_REPAIR', true);


Once you have done that, you can see the settings by visiting this page:


Repair database in WordPress

Remember, the user does not need to be logged in to access this functionality when this define is set.

Checking the WP-Config file

WP-Config.php is probably the only most significant file in your entire WordPress installation. This is where you specify the main points for WordPress to connect your database. If you changed your root password, or the database user password, then you’ll would like to alter this file yet. First factor you ought to forever check is if everything in your wp-config.php file is the same.

define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');


Remember your DB_Host worth might not continuously be localhost. Depending on the host, it can be different. For in style hosts like HostGator, BlueHost, Site5, it’s localhost. You’ll be able to find other host values here.

Some people recommended that they solve their problem by replacing localhost with the IP. It is common to work out this type of issue when running WordPress on a native server atmosphere. For example on MAMP, the DB_Host value when changed to the IP might appear to figure

define('DB_HOST', '');


Solutions that Worked for Others

It is important to note, that these may not work for you. Use at your own risk and make sure that you have sufficient backups if anything goes wrong.

Ran the SQL query by going to phpMyAdmin:

UPDATE wp_options SET option_value='YOUR_SITE_URL' WHERE option_name='siteurl'


Last But not the List ..Most of time it will happend for Installed Plugin ..So please check if you have recently add any new plugin in your site please deactive or delect it ..and try to look that you problem is solve or not . If all of this above solution not work for you then please contact your hosting company they will give you right and worth full solution .


This may be a extremely frustrating error. What have you tried that seemed to work for you? We have a tendency to would be happy to expand on this resource, therefore others don’t must waste as much time finding a solution.


Please Don’t forget to give your suggestion about this error .. Please write if you have any new solution for this error ..Please comment. Thanks for reading

Leave a Reply

Powered by