Blake Howe
3 min readMar 11, 2021

--

“Error establishing database connection” is a warning message that can be somewhat is one of our top support requests. This frequently happens when someone attempts to load a webpage and all you see is a white box with this baffling warning message. This warning implies your website is unable to communicate with a WordPress database connection which beings down your entire site.

The most common errors establishing a database connection in WordPress

Invalid Sign-in credentials

One of the most common issues is that the credentials of databases are not correct. If these are incorrect then. WordPress is unable to bring any information from the database. Although this can be from someone changing the login information in the wp-config, I see this error most often on new installs, or when someone moves hosts.

To check you need to look in your wp-config at these values and compare them to what is set up with your host.

Corrupted Files

Corrupted files can also cause errors in establishing the connection. Files may be corrupted due to failed updates of plugins, themes, or core software of WordPress. To fix these you need to replace the files with fresh copies from the repository.

You can always get the latest version of WordPress from here: https://wordpress.org/download/ and the latest version of your plugins here: https://wordpress.org/plugins/

Corrupted Database

The database can become corrupted for any number of reasons. To correct it you can restore from a backup, open PHP my admin manually repair the table. if you don’t have access to the admin you can add this to your wp-config

define (‘WP_ALLOW_REPAIR’, true);

Once you have added this setting to the file and obviously saved it, access the following URL:

www.test.com/wp-admin/maint/repair.php

WP will display the following interface:

A simple and explanatory interface with two alternatives: repair the database or repair and optimize the database. The difference between the two is that in the second alternative an optimization will be performed after the repair.

The result will be displayed as follows:

The database being unresponsive due to traffic

Databases being over-burden from a traffic spike or an excessive number of simultaneous associations. This happens most of the time with shared hosts as they are using similar assets for plenty of clients on similar servers. You can help with this by using Cloudflare (always on), caching your website, or investing in a VPS.

Summary of how to debug Error establishing a database connection in WordPress

Step 1 First set debugging to true so you can get an error message that makes sense to give to your host or use it to debug with the steps above.

// This enables debugging.
define( ‘WP_DEBUG’, true );

Step 2 Get In Touch With Your Web Host Provider and send the error message from above to give them an idea what they are dealing with.

While trying to contact your host you can be working on these steps.

Step 3 Check If Your Plugin or Theme Files Haven’t Been Corrupted. …

Step 4 Check If Your Database Hasn’t Been Corrupted. …

Step 5 Check Your Database Connection Credentials. …

Step 6 Restore The Default WordPress Files.

Reference

https://wordpress.org/support/article/debugging-in-wordpress/

--

--