How To Fix The Error Of Database Connection To The WordPress Site
- Category: Uncategorized
- Written by: Jitendra Rathod
- Date: October 18, 2022

“Error establishing a database connection” is the dreaded message you wouldn’t want to see on your website. The error basically denotes that your web servers are not able to establish a connection with your database connection. The issue is serious, however, there are some simple steps you can take to fix the problem and get your site running smoothly.
Today, we will better understand the database connection error on a WordPress website, figure out the causes behind it, and learn about the steps to resolve the error. Let’s dive right in.
For WordPress website information like login credentials and posts are stored and organized in a database management system. WordPress uses MySQL, which is an open-source database management system.
On the front end, when a visitor lands on your website, WordPress will use PHP to query the information to be shown on the website.
Now, with the ‘error establishing a database connection’, WordPress is unable to access the database. The pages would not entirely load, and from the backend, you won’t be able to access your WordPress dashboard, too.
If your site uses caches, the users will be able to see the stored copies of the pages. This will allow you to resolve the issues without longer disruptions before the site’s cache refreshes.
The most common cause of this error is incorrect database login credentials. However, there may be some other factors causing it to occur. Here they are:
Now that we know what are the probable causes, here is the step-by-step guide to resolve the error.
Although a serious error, it is an easy one to fix. Here are the steps to troubleshooting the Database Connection error in WordPress. Remember, you don’t need to follow all the steps to mitigate the error. Only move to the next step if one doesn’t work.
Locate the credentials to access your database that is currently used by WordPress. You will find it in your wp-config.php file. Use an SFTP (secure file transfer protocol) to access it.
Look for the data:
DB_NAME: Database Name
DB_USER: Username
DB_PASSWORD: Password
This data should match your MySQL database settings. If it does not, update your wp-config file so that the credentials do not mismatch. The access to MySQL settings, username, and password could be found on your host’s dashboard/control panels.
If your host is not listed in MySQL databases the same as it is named in the wp-config.php file, this error can occur. To add it, simply Create a MySQL hostname and wait for it to propagate through the DNS. After some time, check if the website is working now.
If both of the steps above don’t resolve the issue, it is time to use an in-built tool for repairing the WordPress Database. To access this tool, open your wp-config.php file and add this code at the end.
define(‘WP_ALLOW_REPAIR’, true);
After that, open a new browser tab and enter https://(your website).com/wp-admin/maint/repair.php. It will open the database repair tool. Here, simply click on the ‘Repair Database’ button. When the tool is finished repairing, check your website.
If it’s working, then the corrupted database was the cause. If it’s not, time to move on to the next step. But before that, remember to remove the code you added to wp-config.php as anyone can gain access to your site easily with that.
Too many connections to the database at the same time can cause database connection errors as some providers have limits on the number of connections. If you are sharing a hosting plan, issues with other sites can also mess with your site.
If none of the above, hardware troubles can also cause the error. If the host server is down and a copy of your data is not available, this error may occur. In these cases, reach out to your host and inquire about the issue.
Some additional steps you can take to fix the error of the database connection to the WordPress site.
“Error Establishing a Database Connection” is one of the most common errors site owners face. Though crucial, it is an easy one to fix in some simple steps.
Following these steps, along with the additional fixes, is bound to help you troubleshoot the error.
You can visit our news and projects on a weekly basis. Or you can subscribe to email for regular email updates.
By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.
Chief executive officer
Copyrights © . All Rights Reserved PHPDots Technologies