2 Most Common Solutions for Database Connection Errors in WordPress

WordPress

It’s nine o’clock in the morning and the start of a new business day. You fire up your computer, start your browser, and go get a cup of coffee with the expectation that, upon your return, your website will appear on the screen. You return only to find a terrifying message: ‘Error establishing a database connection’. Your heart sinks as you wonder whether or not you have completely lost your WordPress site.

The first thing you should know is that it is okay to relax. In all likelihood, the error you are experiencing is either due to a server error on your provider’s end or changes to your database that inadvertently altered one of your documents. Ninety-nine percent of the time this error is one that is easily fixed in minutes.

The hardest part of the entire process is troubleshooting to figure out what is causing the error. Below are the two most common solutions. If neither works for you, contact your hosting provider for further assistance.

1. Repairing Your Database

There are times when simple digital glitches can corrupt a database so that a website will not connect to it properly. You’ll know this is the case if you get two different errors when trying to log on as a guest or an administrator. For example, you may get the ‘error establishing a database connection’ message when attempting to log on as a guest, but a ‘one or more database tables are unavailable’ message on your admin login screen. This tells you that your database needs to be repaired.

To do so, use a text editor to edit your wp-config.php file. You’ll want to add the following code:

define('WP_ALLOW_REPAIR', true);

Next, direct your browser to ‘http://www.yoursite.com/wp-admin/maint/repair.php’. From this page, you will be able to repair and optimize your database.

2. Repairing the WP-Config File

In order for your WordPress database to be accessed via a web browser, there is certain information in your wp-config.php file that must match information in the database. Sometimes this information becomes mismatched, leading to an access error. It could be related to updating your root password or your database user password.

To apply the solution, you will first need to login to your host provider’s configuration panel – this is cPanel for most of us – and get the necessary information pertaining to your database. Do this by navigating to the Softaculous>WordPress section. You should see a list of each of your databases. Select the one you want and look at the details.

Next, download and open your wp-config.php with a text editor. Compare the information in this file with the information you found through the cPanel. You will want to look at the following:

define(‘DB_NAME’, ‘database-name’);

define(‘DB_USER’, ‘database-username’);

define(‘DB_PASSWORD’, ‘database-password’);

define(‘DB_HOST’, ‘localhost’);

If any of these four parameters are mismatched, it is the likely cause of your access error. Modify the wp-config.php file so it matches your WP database in cPanel. Upload the modified file and you’re all done. You should now be able to login to your WordPress site as normal.

If neither of these solutions work, you may have another problem to deal with. Contact your host provider for additional troubleshooting assistance.

Share it!Share on FacebookTweet about this on TwitterShare on Google+Email this to someone

Our Recommended Wordpress Web Hosting Provider

WordPress

WHC.CA
Get a 50% Discount by using our link.

WHC.ca

Reliable host, with excellent customer service and an easy one-click Wordpress installation. Our recommendation to host a Wordpress blog.

Leave a Reply

Your email address will not be published. Required fields are marked *