Trying to fix the Error Establishing a Database Connection WordPress error message on your website?
This is a common WordPress error that most websites will encounter at some point. It appears when your site is unable to connect with your database.
It’s one of the scariest WordPress errors because it restricts access to the site for visitors, admins, and other users.
But there’s no need to worry. Like most WordPress errors, this one can also be removed by dedicating some time to understanding the error and implementing common solutions.
In this article, we will show you the exact steps you need to take to fix the Error Establishing a Database Connection WordPress error for good.
Let’s get started.
What does “error establishing a database connection” mean?
The Error Establishing a Database Connection message appears when you are trying to open a page on your WordPress website. To understand why the error occurs, let’s first understand how a page from a WordPress website is loaded into a browser.
It’s important to know that a WordPress website is made of files, folders, and a database.
The files and folders contain the core WordPress files, themes, plugins, media uploads, and other resources. The database stores posts, pages, comments, user data, settings, and plugin configurations, among other resources.
When you try to load a page on your site, WordPress needs to “query” the content for that page from your site’s database.
If WordPress can’t access your site’s database, it can’t access the content that it needs to render the page.
Because it doesn’t have the content that it needs, your site will display the Error Establishing a Database Connection message instead of the content that you expected to see.
What causes the “error establishing a database connection” issue?
Common reasons why WordPress is not able to connect with your database include the following…
Incorrect database credentials: WordPress can establish a connection with the database using the database name, server, username, and password. These credentials are stored in a configuration file called wp-config.php. If the credentials in this file are altered, the connection cannot be established.
Database server unavailability: Some hosts will store your site’s database on a separate server from your WordPress files. If the database server is down or experiencing issues, WordPress cannot establish a connection with the database.
Corrupted database: Server crashes, software issues, improper database handling, etc. are known to corrupt WordPress databases, which causes the “error establishing a database connection WordPress” message to appear on the site.
Now, that you have some understanding of the database error, let’s dive into the solutions.
How to fix the Error Establishing a Database Connection WordPress error
You can troubleshoot and fix the Error Establishing a Database Connection WordPress error by trying the following solutions:
- Check if your database hosting server is down
- Verify database credentials
- Repair WordPress database
- Reinstall WordPress core files
- Deactivate all of your plugins
- Seek help from your hosting provider
Please note that since we don’t know the exact cause of the error, we can’t tell you the exact solution for your website. You need to carry out all the steps below one at a time and see which one works. Keep checking your website after implementing each solution.
But first – try clearing your browser cache
Browser caching is a technique used to speed up website loading times by storing certain static assets on your local computer storage.
Although browser caching helps load web pages faster and improves user experience, it has one small downside in that it can sometimes store pages showing temporary error messages. It then serves that to users, even when the page has gone back to normal.
As such, it’s possible that you’re seeing the Error Establishing a Database Connection WordPress error because of a browser caching issue, rather than an ongoing issue on your site.
So, before trying any other troubleshooting steps, we first recommend clearing your browser cache and checking whether the error persists before diving into the first solution.
1. Check if your database hosting server is down
Before you try any more advanced troubleshooting steps, you’ll first want to make sure your database server is still functioning properly.
If your host offers a hosting status page, you can check that to see any known outages or issues. Or, you can always reach out to your host’s support to ask if there could be a problem with a separate database server.
2. Verify database credentials
Database credentials for a WordPress website are typically created during the installation of the WordPress core. They are stored in the wp-config.php file and used whenever WordPress needs to interact with the database.
Database credentials are usually left untouched, but they can be accidentally altered during a website migration or when a website is hacked.
To check whether the wp-config.php file contains the correct credentials, you need to first locate the correct credentials in your hosting dashboard. Then, open the wp-config.php files and match the credentials stored there.
Here’s how to check database credentials in cPanel, which is hosting control panel used by most popular hosts.
Log into your hosting account and go to cPanel → MySQL Databases. In MySQL Databases, you will find your database name, username, and password.
If you’re not able to view the existing password, you can always create a new password and then add that password to the wp-config.php file.
Next, go to cPanel → File Manager → public_html → wp-config.php.
Right-click on the file and select the View option.
The file will open in a new tab. The database credentials will appear below this sentence: /** The name of the database for WordPress */
Match the credentials in the wp-config.php file with the ones you found in the MySQL Databases.
If there’s a mismatch then you can edit the config file and replace the incorrect credential with the correct one. To edit the config file, right-click on the file and select the Edit option.
3. Repair corrupt WordPress database
If your site’s database has become corrupted, that could trigger the Error Establishing a Database Connection WordPress message in some situations.
Fortunately, MySQL database has a built-in feature that you can use to initiate a repair. For more details, Themeisle has a detailed guide on how to repair the WordPress database using various methods.
4. Reinstall WordPress core files
Although the “error establishing a database connection” message is related to the database, corrupt WordPress core files can also trigger this error in rare situations.
Therefore, removing the corrupt files and reinstalling the WordPress core files could fix the problem.
Since you can’t access your WordPress dashboard, you can reinstall the WordPress core files using an FTP client or an in-browser file management tool like cPanel File Manager.
In this article, we will use the hosting account to access the backend of your website, but the basic process is the same if you’re connecting directly via FTP.
To reinstall WordPress, the first thing you need to do is download the latest version of WordPress to your local computer and unzip the file.
Next, open your hosting account, go to cPanel → File Manager → public_html. Select the Upload button located on the top of the screen and upload the files your unzipped on your local computer.
You will be asked to confirm whether you want to replace your existing files. Hit the Confirm or Yes button and wait for the files to be replaced.
Then check if that helped remove the Error Establishing a Database Connection WordPress message from your website.
5. Check for plugin issues
Like the WordPress core, corrupt themes & plugins can also trigger the Error Establishing a Database Connection WordPress error message in rare situations.
We recommend starting by checking your plugins, as they’re more likely to be causing an issue than your theme.
To learn whether a plugin installed on your website is causing the error, here’s what you need to do:
To begin, connect to your server via FTP or use cPanel File Manager to access the files on your server. We’ll use File Manager for this guide, but the basic idea is the same if you’re using an FTP client.
Once you’ve connected, navigate to public_html → wp-content → plugins.
Then, rename the plugins folder to plugins-deactivated.
As soon as you rename the plugins folder, all of the plugins on your site will be deactivated. Now, check whether the database connection issue is gone.
If the issue persists, then your plugins are not the culprit. You can rename the plugin folder to its original name (i.e. ‘plugins‘).
If the issue goes away, you know that one of your plugins is causing the problem. You can then use the same approach to disable individual plugins inside of the plugins folder. For example, if the plugin’s folder is cool-plugin, you would rename it to cool-plugin-deactivated to disable just that plugin.
Once you find the troublesome plugin, you can replace it with an alternative plugin or contact the plugin’s developer for help.
6. Seek help from your hosting provider
After trying all the solutions listed in this article, if you still can’t remove the error from your WordPress website, then it’s time to seek help from your hosting provider.
They should be able to offer solutions that will get your website up and running in no time.
If you find that your host’s support isn’t very helpful, you might want to switch to one of the providers from our best WordPress hosting roundup.
Fix the Error Establishing a Database Connection WordPress issue for good
The Error Establishing a Database Connection WordPress issue appears when you are trying to open a page of your WordPress website.
The error indicated that the site cannot connect with the database.
The database is an important part of a WordPress website because it stores posts, pages, comments, user data, settings, plugin configurations, and other resources.
Without access to the database, the browser cannot open a web page.
And access to the database is typically lost due to reasons like incorrect database credentials database server unavailability, corrupted database, and hosting server issues.
To re-establish access to the database, take the following steps:
- Check if your hosting servers are down
- Verify database credentials
- Repair corrupt database
- Reinstall WordPress core
- Deactivate all of your plugins
- Seek help from your hosting provider
If you have any questions about the “error establishing a database connection WordPress” message, let us know in the comment section below.
Was this article helpful?
Thanks for your feedback!
Keep reading the article at WPShout. The article was originally written by Sufia Banu on 2023-09-18 13:28:04.
The article was hand-picked and curated for you by the Editorial Team of WP Archives.