How to fix "Error establishing a database connection" in Wordpress. Causes and solutions

How to fix "Error establishing a database connection" in Wordpress. Causes and solutions

"Error Establishing a Database Connection" is a common issue that occurs on WordPress. When this error occurs, it means that your WordPress site is unable to connect to the database where it stores its data. This can be frustrating for website owners and visitors alike.

There are several possible causes for this error. Understanding these causes can help you troubleshoot and resolve the issue more effectively.

Preparing for Troubleshooting

Before you start troubleshooting the "Error Establishing a Database Connection" issue, it is essential to create a backup of your site. This ensures that you can restore your website to its previous state if any unexpected issues arise during the troubleshooting process.

Troubleshooting Steps

Checking Database Credentials

One of the common causes of this error is incorrect database credentials. To resolve this issue, you need to verify that the database credentials in your WordPress configuration file (wp-config.php) are accurate. Ensure that the database name, username, password, and host information are correctly specified.

It is recommended to double-check the database credentials to avoid any typos or mistakes that may prevent the connection.

If you use a shared hosting - you can find your database credentials in hosting control panel. If you use VPS or physical server you can ask your system administrator for check it.

Repairing Corrupted Files

Corrupted files can also lead to the "Error Establishing a Database Connection" problem. WordPress relies on various files to function correctly, and if any of these files become corrupted, it can affect the database connection.

To fix this issue, you can try repairing the WordPress core files by using the built-in repair functionality. Alternatively, you can manually replace the corrupted files with fresh copies obtained from a clean WordPress installation.

It is crucial to keep your WordPress files up to date to minimize the risk of file corruption.

Increasing Memory Limit

In some cases, the "Error Establishing a Database Connection" error can occur due to insufficient memory limit allocated to WordPress. When WordPress exceeds the allocated memory, it can result in database connection issues.

To address this problem, you can increase the memory limit by modifying the PHP configuration settings. Locate the php.ini or .htaccess file and adjust the memory limit values accordingly. Alternatively, you can reach out to your hosting provider for assistance in increasing the memory limit.

Having an adequate memory limit ensures smoother database operations and reduces the chances of encountering this error.

Checking Database Server

The issue may not be with your WordPress site or its configuration, but rather with the database server itself. It is essential to check if the database server is running correctly and is accessible.

The database server could stop working due to various reasons. For example, when the system runs out of free memory or disk space, it can crash.

Ensure that the database server is up and running, and there are no network connectivity issues. You can try connecting to the database server using a database management tool or contacting your hosting provider for assistance in troubleshooting the database server.

Switching Hosting Provider

If you have exhausted all other troubleshooting steps and are still experiencing the "Error Establishing a Database Connection" error, it may be worth considering switching your hosting provider. Sometimes, the issue can be related to the hosting environment or server configuration.

But first try contacting the support of your current hosting provider. It may have malfunctioned or is undergoing maintenance which has caused your site to fail.

Research and compare different hosting providers that specialize in WordPress hosting. Look for providers with reliable database performance and excellent customer support to minimize the chances of encountering this error in the future.

Deactivating Plugins

Conflicts with plugins can also lead to the "Error Establishing a Database Connection" issue. To identify if a plugin is causing the problem, you can deactivate all the plugins on your WordPress site and check if the error persists.

If the error disappears after deactivating the plugins, you can reactivate them one by one to determine which plugin is causing the conflict. In some cases, updating or reinstalling the problematic plugin can also resolve the issue.


In conclusion, encountering the "Error Establishing a Database Connection" error in WordPress can be frustrating, but it is not insurmountable. By following the troubleshooting steps outlined in this article, you can effectively identify and resolve the issue.

Remember to check your database credentials, repair corrupted files, increase memory limits, and ensure the database server is functioning correctly. If needed, consider switching to a more reliable hosting provider and be mindful of potential plugin conflicts.

Fixing the "Error Establishing a Database Connection" error will improve the stability and performance of your WordPress site, providing a better experience for both site administrators and visitors.

Read more