In this article, I’m going to show you how to fix Error Establishing a Database Connection in WordPress. For WordPressors, this is a really common error. I’ve been through this many times and it took me a quite bit of time to figure it out. So today I’m gonna discuss why this error occurs and the possible ways to rectify it as well.
Please make a backup of your WordPress website and database before proceeding. It is always a good practice.
Why this Database Error Occurs?
Apparently, you get this error because WordPress is unable to establish a database connection so the question arises: Why WordPress is unable to establish database connection?
Now the answer to this may vary because there’re a number of reasons which cause this error. It could be that your database login details are incorrect or changed. Or it could be because of the a server side issue.
How to Fix Error Establishing a Database Connection in WordPress
Let’s take a look at different things we should try while troubleshooting this problem:
Does your domain.com/wp-admin has the same error?
The very first thing you should check is if you’re getting this same error on both front-end and back-end admin panel. If you’re getting the same error, we’re good to go on next step. But if not, then you need to repair your site database.
You can repair your database by adding the following line of code in your wp-config.php file.
After doing this, you can view settings by navigating through this page:
Check WP-CONFIG file:
Wp-config.php file in WordPress contains your website connection details with the database. You need to check that everything in this file is same and doesn’t conflict in case your change your credentials. Check out for these lines of code specifically:
Sometimes IP works instead of locahost. In that case you’ll have to write this line of code:
define (‘DB_HOST’, ‘127.0.0.1’);
This IP would vary based on the web hosts.
I hope that after reading this article, you’ll understand how to fix error establishing a database connection in WordPress. If you’ve any questions, feel free to ask in the comment box and I’d be more than happy to assist. If you liked this article, please subscribe to our YouTube Channel. You can also follow us on Facebook, Twitter and Pinterest.