Seeing the message “error establishing a database connection” is a common error among WordPress users. Today we are going to tell you how to troubleshoot and fix this error yourself without expert administrative support.
First, it is important to backup your website before making any changes to the database. This will ensure you have the latest version of your website, in case anything should go wrong during this process.
Why am I receiving this error?
WordPress is comprised of a database and lots of files. You are receiving this error because WordPress cannot establish a connection to its database. This could be for a variety of reasons: your database login information is incorrect; your server is down or otherwise unresponsive; your server has been corrupted; etc. We will delve further into each of these possibilities.
Start by checking both the back-end and front-ends of the website. On the front-end (when you enter in the URL of your website), you should see the database error. On the back-end, (when you login to the wp-admin page) check to see if you are seeing the same database error.
If you are seeing the same error, your wp-config.php file may need to be repaired. If you are seeing a different error, this is a sign that your database needs to be repaired.
In the WordPress editor, go into the wp-config.php file and add the following code:
Your wp-config.php file is an extremely important file that works to configure your database. If there is an error in this file, your database may not be working properly. When you set up your database with your host (GoDaddy, BlueHost, HostGator, etc.) you chose a username, password and other information to login to your database. You should check this wp-config.php file to make sure that the database credentials in here match the ones in your hosting account.
If this file does not produce any errors, there may be something wrong with your server. It is recommended that you call your hosting provider and ask them if your MySQL database is responsive. The customer service representatives can find issues that are wrong with your database and change permissions if necessary. There may be some information that has been changed without you knowing about it.
Finally, uploading a fresh copy of WordPress to your website may resolve this error. In which case, you will want to have a backup as noted in the beginning of this article.
We hope this helps to resolve any issues you are having with your WordPress database!