Common WordPress Errors: Error Establishing a Database Connection

Posted by & filed under Troubleshooting, WordPress.

Error Establishing a Database Connection

 

If you clicked on this article, you are probably looking for a working solution to a technical issue you may have come across regarding an error establishing a database connection upon accessing your website on WordPress.

For the average user WordPress may crop up some errors that happen to be fairly common. These can range from a blank white page where the blog post should be updated, or an error proclaiming the maximum memory limit being exhausted, or even a plug-in that cannot be uploaded.

Most frequent, however, is the error regarding database connectivity. The error can seem confusing, but you are not alone. Whether you consider yourself tech-savvy, or clueless as to the first letter of coding, this article will help you resolve the issue so you may return to your uninterrupted blogging and posting.

 

WordPress is allegedly the most popular blogging platform available on the Web, due in part to how easy it is to access and manage. This system hosts nearly 60 million websites alone. The company behind this system, Automattic, first launched this open-source project in 2003, from where it gathered steam and continued to develop and expand.  Today, giants such as CNN, TED, and the NFL all publish on WordPress.

What is the Error, “error establishing a database connection”?

If you attempt to access or view your website or blog, and are met with a blank white page that simply states “error establishing database connection”, the problem can be chalked up to one of a handful of reasons, which will be explored in detail later.

As far as the error itself is concerned, it can be explained in terms of what WordPress itself is based on; PHP – a scripting language, and (in most cases) MySQL – a relational database management system. Both these systems were first developed around 20 years ago, and serve different purposes. They are the engines behind your website or blog, making sure your words and content actually appear to viewers.

Your personal PHP is used to access your MySQL database to retrieve the information necessary; this could mean the PHP contacts the MySQL database to draw up information regarding your details, publishing date, and the content of the page itself.

These processes occur in the small time is takes for a page to load. When you come across an error establishing database connection, it means that the connection between the PHP and MySQL was broken or interrupted; the two databases could not communicate with one another to pull up the required data.

What results is a blank page. A blank page means reduced revenue for you, since viewers can no longer access your content and can cause major losses in sales for Business E-commerce sites.

 

Possible causes

  1. Incorrect Login Details : Your Database login information could be incorrect; if your Database login details have recently been changed, then WordPress will not be able to connect to the Database tables properly with the old credentials.
  2. Server Down :The server could be down for maintenance; this is a fairly common occurrence, and means that the issue could be from the server’s end. This issue can resolve from your server host’s end.

To check if above 2 cases are the causes, you can check the main site page, wp-admin page (sitename.com/wp-admin) to check if the same error establishing database connection is also appearing there.

  1. Corrupted Files: Any number of things could corrupt a database until it no longer works. This could be anything from a faulty Theme or Plugin, or links that lead to infected sites.
  2. Database Corrupted :Your MySQL could be corrupted.

 

How to resolve the error

The first step is identifying which of the four problems is causing the error establishing database connection.

Fix 1 : If, upon checking the wp-admin page for a similar error, you come across a different error stating that “one or more database tables are unavailable. The database may need to be repaired”, it means that the database has been corrupted. In this case it would be best to restore the database from a previous working date from the backup.

Fix 2 : The next step is accessing your wp-config.php file; this file stores all the details and configurations of your WordPress Install along with the Database login details as well. To do this, you must log in to your cPanel or access the files using the FTP login and open the wp-config.php file from the site’s directory, where you installed WordPress.

The next step is to add this line of code at the end of your wp-config.php file, above the line “/* That’s all, stop editing! Happy blogging. */”:

Upon this, you must navigate to your website  www.yourwebsite.com/wp-admin/maint/repair.php

You will now be redirected towards a page that gives you two options; to repair your database, or to repair and optimize. You can pick either of the two.

 error establishing a database connection

Now check back to see if everything is in working order. If it is, then you must remove the last line of code you manually added to the end of your wp-config file, and then close the tab and continue.

Fix 3 : If the error establishing database connection persists, then that means the database corruption might not be the only issue, and the login credentials could be posing a problem.

Near the top of your wp-config file, the Database login details will be listed. These details will look something like this :

 

Check to make sure all the information entered is correct. In case the login credentials are incorrect, you can either update the ones entered in your database; or create new ones.

How to check if your MySQL login credentials are working

Create a new “dbtest.php” file in your directory, and paste the following code in it:

Now run this file from your browser by accessing : http://{yoursitename.com}/dbtest.php

The error establishing a database connection is a fairly common one, and is easily solvable. The key is finding the problem – whether it lies in a corrupted database that needs to be reconfigured, or log-in credentials that need to be corrected. Since WordPress is a server with constantly updating versions, the code may need tweaking from time to time in order to work, but the solutions provided above are sure to fix this error and allow continued access to your personal domain.

 

Leave a Reply