Last Updated on April 24, 2022 by WP Knowledge Hub
There are few things more aggravating than discovering that your website is down, especially if you rely on it for a living. The “Error Establishing a Database Connection” warning indicates a major problem that prohibits all access to your site, thus resolving it should be a top priority. However, if you’re unfamiliar with how WordPress website files are connected to a database, this might be a perplexing issue.
Understanding the Error “Establishing a Database Connection in WordPress” message
So, why are you getting this message? Quite simply put, your WordPress files can’t find their associated database.
WordPress is basically a marriage between a set of files and a database. Your theme templates, your plugins and the core files that make WP function are stored in a server, and the content of the settings, pages and posts that make use of those files are stored in a database.
Without one part or the other, your WordPress website won’t work. Fortunately, as WordPress errors go, the database connection error is typically the easiest one to solve. The most common issue by far, is that the .wp-config file is pointing to the wrong database name, user, or password.
Common Causes of the Error Establishing a Database Connection
Some other websites will tell you that your core files might be corrupted and your database could be corrupted. I’m not saying that’s impossible, but in over ten years of WordPress development, I have never seen that happen. If you are seeing Error Establishing a Database Connection, the error is always because of:
- Incorrect database login credentials: the most typical cause of the Error Establishing a Database Connection is that your database login credentials are incorrect in the .wp-config file. The database name, username, or password could all be wrong, or it could be only one of them (keep in mind that these login credentials are not the same as the ones you use to access your WordPress backend). If you don’t know how to get your database credentials, you need to contact your hosting support.
How to Fix the Error Establishing a Database Connection in WordPress
Check Your WordPress Database Credentials
This should be the first step in your troubleshooting because it is the most likely cause of the error. The first step is to figure out what credentials WordPress is using to access your database right now.
This information is stored in your site’s wp-config.php file. You can find this file in the root folder of your website’s server.
Inside the File Manager, select wp-config.php and EDIT it. Here, look for three things: the database name, username, and password. They should be near the top of the file.
With this information in mind, make sure that the database that is storing your website’s information is actually the one listed in the Database Name. If it’s not, you need to access your control panel, find the Database section, find the right database, find its username and password, and change the credentials in your .wp-config file.
Once that’s done, you’ll have access to your website again!