WordPress is world best CMS. There are billions of website using WordPress to manage websites. If you have been surfing the web for a while, you have at least seen this error (error establishing a database connection) a few times. Error Establishing a Database Connection is one of those curses that could be caused by many reasons. As a WordPress beginner, this could be awfully frustrating specially when it happened on its own without you changing anything.
You also like to Read…
We ran into this issue yesterday on our own site. It took a little over 15 minutes to detect and fix the problem. While doing the research to find possible causes. I realized that there was no good article that covered everything.
In this article, we will show you how to fix the error establishing a database connection in WordPress by compiling a list of solutions all in one place.
Why do you get this error?
Well in short, you are getting this error because WordPress is unable to establish a database connection. Now the reason why WordPress is unable to establish a database connection can vary. It could be that your database login credentials are wrong or have been changed.
- It could be that your database server is unresponsive.
- It could be that your database has been corrupted.
In our experience, majority of the times this error happens because of some sort of server error however there could be other factors as well. Lets take a look at how to go about troubleshooting this problem.
Step 1: Determine Error Establishing a Database Connection
Are you encountering the same error when you try to enter the website URL (front-end), and when you attempt to login to /wp-admin/ (back-end)? If the error is the same, i.e., error establishing a database connection, move onto the next step.
However, if you encounter the following error when trying to login to /wp-admin/, your database has been corrupted:
“One or more database tables are unavailable. The database may need to be repaired”
In your root WordPress file directory, you must locate your wp-config.php file. You must do this to enable WordPress’ built-in repair feature.
Launch Filezilla –> (WordPress install folder) –> public_html
Right-click the wp-config.php file and select a code editor, such as Sublime Text Editor to open the file.
After you’ve opened the wp-config.php file, add the following line at the bottom of the file:
Now navigate to:
Replace “yourwebsite.com” with your actual URL
You will see the above-mentioned options. We recommend you to choose the “Repair and Optimize Database” option. Although it takes more time, it is a more comprehensive attempt to fix the issue.
Did this method fix WordPress error establishing a database connection? If so, congratulations! If not, carry on reading this guide to find another fix regarding the error.
Step 2: Check Database Login Credentials in wp-config.php
WP-Config.php is probably the single most important file in your entire WordPress installation. This is where you specify the details for WordPress to connect your database.
If you changed your root password, or the database user password, then you will need to change this file as well. First thing you should always check is if everything in your wp-config.php file is the same.
Some folks suggested that they fixed their problem by replacing localhost with the IP. It is common to see this sort of issue when running WordPress on a local server environment.
IP’s will vary for online web hosting services.
If everything in this file is correct (make sure you check for typos), then it is fair to say that there is something wrong on the server end.
Step 3: Reset Username and Password
You must ensure that the username and password in your wp-config.php file match the in phpMyAdmin. In our case, it’s “MySQL Access”.
If the username and password do not match, open your wp-config.php file and edit it to include the values from the “MySQL Access” panel. That’s it! If you were attempting to do this via cPanel, you’d have to put in a lot more effort.
I hope you like this article. If yo really like this article please don’t forget to share on your social media accounts. Thanks a lot for reading my article please also give us a like. I also write many articles on WordPress problems and others tips and trick. So if you need updates from my blog please fill the form given below.