Fix Error Establishing a Database Connection In WordPress

error establishing a databse
Written by Mohammed Rafi

Error establishing a database connection is most common error faced by WordPress user.Nobody loves their blog to encounter with this problem.How long our site is going to be in down is that much of traffic we are going to loss same as to revenue.


Read This: Free Keyword Research Tools

What is Error Establishing a Database Connection?

This error happens when PHP unable to connect your MySQL Databases to built your site.There are various reasons behind your site’s PHP code not connecting to your Database.

Why WordPress Error Establishing a Database Connection Occurs

Before going to know the reason behind this error let us know how WordPress works.Your WordPress site is built with two languages, PHP on the client side and MySQL Database on the server side.

MySQL Stores all the information like login details,post and page datas,plugin information etc.Your PHP code has other informations like wp-config.php,index.php etc.

When someone visits your site, PHP code is executed, and it fetches data from MySQL to build your site.If your PHP code is unable to get the data from MySQL “Error Establishing a Database Connection ” arises.

error establishing a database connection wordpress

The Possible reason behind this is

  • Incorrect Login credentials
  • Corrupted Database
  • Corrupted Files
  • Errors from Hosting Company Side

Read This:Add Bigrock Custom Domain

Fix the Error Establishing a Database Connection in WordPress

Note: Don’t forget to take backup before fixing the errors

Before moving further check whether the same problems arise in both front-end( and back-end(

If both have same error(error establish a database connection) follow the second method.If you find this error(one or more database tables are unavailable)follow below method.

Repair the database

If you find this error “one or more database tables are unavailable” you need to repair your database.

To repair your database follow these simple steps

Open your wp-config.php file and add the below code on the bottom

define('WP_ALLOW_REPAIR', true);

Now go to (replace it with your site URL)
Now click “Repair and Optimize Database
After finishing repair and optimize remove the added code from wp-config.php

Check wp-config file

In order to confirm whether your login credentials are correct you need to check the config file.

Open wp-config file

Check for below codes in the wp-config file.Confirm both of them are same

define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');
For DB_HOST the value is localhost for most of the hosting but sometimes it change.
If everything is same then there is any other problem with your server.

If you have any other problems in overcoming this error kindly inform us through the comment section.If you have any other solutions kindly tell us.Do share it with your friends



Get more stuff like this

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

About the author

Mohammed Rafi

Mohammed Rafi is the administrator of seofari.He likes to post about SEO, Computer tricks etc.Apart from blogging he is currently doing his final year B.E

Leave a Comment