[Fixed] Error Establishing A Database Connection In WordPress

WordPress developer

You might have seen above error If you are a blog owner or visited a blog having connection issue. Error establishing a database connection issue is really frustrating error in WordPress when you are dealing with your own blog.

There are many reasons behind this issue. In this article we are discussing all issues behind error establishing a database connection in WordPress and solution to each of those.

Sometimes it happens without doing anything. Last week we have been facing the same issue and spent almost 30 minutes to fixed connection issue. We didn’t find a complete guide for this problem anywhere so, decided to write a detail fixed for this error “Error establishing a database connection “

The Main Cause Of “Error Establishing a Database Connection In WordPress” ?

The actual reason is your WordPress blog couldn’t establish a connection with MYSQL Database server. there may be several reasons.

Database table corrupted or not found inside database. May your database credential have changed? Currently your database server overloaded and not giving response.

Majority of times, if you haven’t changed anything -then reason could be some sort of database server error.

Check If issue occurs for ‘/Wp-Admin’ directory?

  • Go to your WordPress admin area by simply go to “yourblog.com/wp-admin”. in that case if you are getting the same error - Error establishing a database connection then you have a other subsequent fix.

  • If you are getting error like - “One or more database tables are unavailable.”  then database may need to be repaired as you may missed some table that your blog or plugin required

Make sure that - before applying any changes take your database backup first.as this required some expert level editing in your WordPress installation.

To repair WordPress database, simply add a single line in your wp-config.php file available in your root directory.

define('WP_ALLOW_REPAIR', true);

After adding above line simply access - www.yoursite.com/wp-admin/maint/repair.php and click on repair database button. If your issue remains unresolved then you need to continue reading article and go for second reason.

Reason: WordPress Database Credential Changed

Sometimes you changed your MySQL database password and forget to update those details in your wp-config.php file which is main crucial file in WordPress which holds all database connection information.

By Using FTPO Software or Webhosting cPanel , you can check wp-config  to verify your database details matching with current.

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

DB Host value will be different based on your web hosting provider like HostGator, Dream host, Bluehost. Majority of users had this issue when they migrate their web hosting or domain name and forget to change wp-config.php values.

My SQL Database Server - WordPress Database Unresponsive For Some Period of Time

Sometimes if you buy cheap web hosting and your site have heavy traffic that could result in MYSQL server downtime due to number of open connections. if you have well popular site, I suggest please shift to best web hosting provider who provide good server response on a heavy load environment.

There might be the reason sometime web host was under maintenance so, some period database may get down. please contact your web hosting support team.

We tried to give each possible cause for this error, feel free to share your experience in this particular situation so, that can help others to save time to fix database connection error.