
If you’re running a WordPress site, seeing the “Error Establishing A Database Connection” can be alarming. This error occurs when your website can’t connect to its database, which is crucial for loading your site’s content and data. As a result, your website becomes inaccessible to visitors, leading to a potential loss of traffic and credibility. Whether using WordPress hosting or managing your server, this issue can impact your site’s functionality and user experience.
Therefore, addressing this error as soon as possible is essential. It not only restores your site’s functionality; it also ensures a better user experience, and it maintains your site’s SEO ranking. So, in this tutorial, we’ll walk you through the various steps, including what the error comprises and why it happens.
Then, we’ll explore common causes behind the error, leading to step-by-step solutions to fix it. Moreover, we’ll find some preventive measures to avoid future occurrences. By the end, you’ll be equipped with the knowledge to troubleshoot and resolve this error, ensuring your WordPress site remains up and running smoothly.
KEY TAKEAWAYS
- Verify and update your database credentials in wp-config.php.
- Enable and use the WordPress database repair tool.
- Check your database server status, permissions, and connection limits.
- Update your WordPress site URL using phpMyAdmin if needed.
- Replace any corrupt core WordPress files.
- Deactivate and reactivate plugins and themes to find conflicts.
- Restore your database from a backup if other methods fail.
- Verify and update your domain’s nameservers and A records.
- Contact support teams, reboot your server, or restore from backups as alternative solutions.
- Implement preventive measures like automatic backups and regular updates.
Table of Contents
What Is Error Establishing A Database Connection?
The “Error Establishing A Database Connection” appears when WordPress can’t connect to its database. This error occurs when the connection information in your site’s configuration file, wp-config.php, doesn’t match the database credentials.
Let’s understand it in simple words. This error indicates a breakdown in communication between your website and its database. WordPress uses a database to keep all your site’s content and settings. When WordPress cannot access this database, it displays an Error Establishing A Database Connection message.
| Error Code | Error Establishing A Database Connection | 
| Error Type | Database Error | 
| Error Causes | Common causes are: 1. Incorrect database credentials 2. Mismatched details between wp-config.php and the WordPress database 3. Corrupted core files 4. Database corruption | 
There are multiple use cases where you may encounter this error, some of which are given below:
- Incorrect Database Credentials
- Corrupt Database
- Server Issues
- Corrupted Core Files
- High Traffic
The question is about the impact of the Error Establishing A Database Connection error on the website. Does it affect your site?
When this error occurs, your entire website becomes inaccessible. Visitors won’t be able to see any of your content, and you’ll lose traffic and potential revenue. Additionally, prolonged downtime can negatively affect your site’s search engine rankings, making it essential to fix this error quickly.
Therefore, understanding this error and fixing it fast can help maintain your site’s uptime and performance.
Causes of an Error Establishing A Database Connection
Understanding the root causes of the WordPress Error Establishing A Database Connection is key to resolving it quickly. Here are the most common reasons why this error occurs:
Incorrect Database Credentials: Your WordPress site connects to its database using specific credentials: a database name, username, host, and password. If any of these details are incorrect, WordPress won’t be able to access the database, leading to a database error.
Corrupt Database: A corrupt database can prevent WordPress from establishing a connection. This corruption can occur for various reasons, such as an unexpected server shutdown or a malicious attack.
Database Server Down: If your database server is down or experiencing issues, your WordPress site won’t be able to connect to it. This can happen due to server maintenance, heavy traffic, or unexpected outages.
Too Many Concurrent Connections: Your WordPress hosting environment might have limits on the number of database connections. If your site exceeds these limits, the database might refuse additional connections, resulting in this error.
Corrupted WordPress Files: Sometimes, essential WordPress files can get corrupted due to failed updates, plugin conflicts, or hacking attempts. Corrupted files can disrupt the connection to the database.
Once you recognize the specific cause, then you can apply the appropriate fix to get your WordPress hosting site back online. We offer detailed steps in the sections below that help to troubleshoot and resolve the issue.
Optimize your WordPress website’s performance.
Hosted’s WordPress Hosting ensures optimal database performance.
How to Fix an Error Establishing A Database Connection
There are several methods to resolve Error Establishing A Database Connection in WordPress. Let’s start with the easiest ones and then head to more complex ones.
Check Database Credentials
Database credentials can change for several reasons. For example, these occur when you migrate your website from one hosting provider to another. This requires different database settings. You might also update your database password for security purposes. Moreover, sometimes, hosting providers change the database server configurations, affecting your credentials.
To ensure your database credentials are correct, you need to check the wp-config.php file, located in the root directory of the WordPress installation. This file contains the necessary settings for WordPress to connect to your database.
You can access the wp-config.php file in two ways:
- Access your website’s files via an FTP client like FileZilla. This approach is more appropriate if you can’t access your WordPress hosting account; otherwise, go with the second one given below.
- Log in to the WordPress hosting control panel and navigate to File Manager. Find the wp-config.php file in the root directory to confirm database credentials.
Remember, if you’re using the first approach, you’ll need to download the wp-config.php file, make the required edits (if needed), and re-upload it to your web server using FileZilla. However, if you’re hosting your website at Hosted, you can directly edit the wp-config.php file in your web browser using cPanel’s File Manager feature.
Regardless of the approach you use, open the file and look for the following lines of code:

Here’s an example of what the database settings section of the wp-config.php file might look like:
define('DB_NAME', 'your_database');
define('DB_USER', 'your_username');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'your_host');Ensure that the values for DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST match the credentials provided by your WordPress hosting provider. If any of these values are incorrect, update them accordingly and save the file.
Verifying and correcting these credentials will resolve the Error Establishing A Database Connection and restore your WordPress site. If the error persists after updating these details, you may need to explore other potential solutions, which we’ll cover in the next sections.
Repair WordPress Database
Over time, your WordPress database can become corrupted for different reasons, such as plugin conflicts, failed updates, or server issues.
A corrupted database prevents your site from functioning correctly and can lead to errors such as the WordPress Error Establishing A Database Connection. In this case, repairing the database can fix these issues and restore your site’s functionality.
The point is: how can you enable the repair feature in WordPress?
Luckily, WordPress has a built-in feature to repair and optimize the database, but it’s not enabled by default. To use it, you’ll need to modify the wp-config.php file. We’ve already covered how to open and edit the wp-config.php file; refer to the previous section to recap.
Once you open the wp-config.php file, add the following line of code to enable the repair feature:
define('WP_ALLOW_REPAIR', true);Save the file and go to the following URL in your web browser, replacing yourwebsite.com with your actual domain name:
http://yourwebsite.com/wp-admin/maint/repair.phpYou’ll see the database repair page with two options: Repair Database and Repair and Optimize Database. Choose the Repair Database option to start the process.

After the repair is complete, remove the define(‘WP_ALLOW_REPAIR’, true); line from your wp-config.php file to prevent unauthorized access to the repair tool.
If the problem persists, further troubleshooting may be required.
Check Database Server
Sometimes, the Error Establishing A Database Connection occurs because your server is down. To check if the server is running:
Log in to the web hosting control panel. Next, navigate to the Databases area and click on phpMyAdmin.

Head to the Status tab, click on Server, and ensure the database server status is active and running.

Furthermore, in some cases, network problems between your web server and the database can also cause this error. If there is an interruption in the communication channel, WordPress won’t be able to establish a connection to the database.
In this case, it’s good to contact your hosting provider to find out if all WordPress sites on the same server are going through the identical issue. If so, the problem is on your hosting provider’s end.
Remember: your database servers can only handle a specific number of simultaneous connections. If the limit is exceeded, additional connection requests will be denied, and this will cause the Error Establishing a Database Connection. This issue is more common in shared hosting environments where resources are limited.
For this cause, a sudden spike in traffic can overwhelm your database server, especially if it’s not optimized to handle high loads. This surge in traffic can exhaust the server’s resources, leading to the error. To resolve it, use plugins like W3 Total Cache or WP Rocket to minimize your server back-end requests.
Moreover, if the database user doesn’t have the necessary permissions to access the database, WordPress will be unable to connect. This can happen due to misconfigurations or changes in the server settings.
Therefore, ensure that the database user specified in your wp-config.php file has the required permissions. Do this through your hosting control panel’s database management tool (like phpMyAdmin) by checking the user privileges.
For this, navigate to the cPanel > phpMyAdmin > Databases tab and click on Check privileges for your desired database.

You’ll see all the user privileges there for the particular database
Alternatively, use the following steps to find out if the user has the required permissions:
- First, go the cPanel > Files > File Manager.

- Then, navigate to the WordPress installation root directory, which is public_html. Click on the + icon in the top-left to create a new PHP file.

- A pop-up will appear requesting the name and path of a new file. You can name this file anything; we used testFile.php for this tutorial. After that, ensure the file will be created in /public_html directory. Finally, click the Create New File button.

- Next, locate the testFile.php and click Edit.

- A new pop-up screen will appear; click Edit. We don’t need to back up this file as it’s currently blank.

- Now, paste the following code in testFile.php and click Save Changes:
<?php
    $link = mysqli_connect('localhost', 'username', 'password');
    if (!$link) {
        die('Could not connect: ' . mysqli_error());
    }
    echo 'Connected successfully';
    mysqli_close($link);
?>Don’t forget to replace the database username and password, which you can find in the wp-config.php file.

- Open a new tab on your web browser and try to access the testFile.php file using the link in the following format:
yourdomain.com/newFileName.phpWhich is as follows in our case:
https://www.domain.online/testFile.php
If your WordPress debug script doesn’t give an error, your database user has the necessary permissions. Otherwise, you need to adjust user privileges in phpMyAdmin to create a successful database connection.
If you still cannot resolve the issue, contact your hosting provider. They can check the server status, identify if there is an issue, and help you restore your database connection. Show them the error messages you’ve encountered and details about your troubleshooting steps.
Check for Corrupt Plugins or Themes
If the issue is not database-related, then corrupt plugins or themes might be causing the Error Establishing A Database Connection in WordPress. To fix this, deactivate the last WordPress plugin you installed.
If you have multiple third-party software, we recommend deactivating all plugins and reactivating them singly to identify the culprit. There are two ways to deactivate all plugins at once:
- Using WordPress admin panel
- Using an FTP client like FileZilla
Let’s start with the first method. For this, log in to your WordPress admin panel.
Go to the Plugins > Installed Plugins section. Select the checkbox labeled Plugins at the top. This will select all plugins at once. Then, pick Deactivate from the bulk actions dropdown and click Apply to deactivate all plugins.

Now, click Activate to activate one plugin at a time to see if the error persists. If it does, you’ve found the plugin causing this error. If not, activate it and move to the next plugin’s activation process. We also recommend that you enable auto-updates for plugins to keep them updated.

Use this second method when you cannot access your WordPress admin dashboard. For this, open FileZilla and connect it to your web server using FTP credentials provided by your hosting provider.

Once connected, navigate to public_html > wp-content. Right-click on the plugins and choose Rename to rename it as plugins_old (you can name it anything you want).

Now, you should be able to access your WordPress admin panel. Rename folders to their original names and try activating plugins one by one to identify the root cause of the error. Once recognized, fix the problematic plugin or choose alternatives.
Important: You can also rename theplugins folder using File Manager, one of the features of the hosting control panel. To use it you must have access to the web hosting account. If you have already done this, go to cPanel > Files > File Manager > public_html > wp-content. Locate the plugins folder and rename it.
If the issue is not with the plugins, you might have a corrupted theme. Remember, you cannot simultaneously disable all themes from the WordPress admin dashboard. Rather, activate them individually from WordPress Dashboard > Appearance > Themes.
However, if you’re using an FTP Client or have access to the hosting control panel, you can disable all themes in one go. To do this, rename the themes folder (located in /public_html/wp-content). Unlike plugins, the default theme will automatically reactivate when you revert the themes folder to its original name.
Fix Corrupted WordPress Core Files
If deactivating plugins and themes doesn’t fix the issue, you may need to replace the core WordPress files. To do this, go to the WordPress site and download the latest version of WordPress.

Unzip the downloaded zip file to your local machine.
After that, use an FTP client to connect to your website’s server. Go to the root folder of your WordPress installation. Upload the wp-admin and wp-includes folders from the extracted WordPress files on your computer to the server, overwriting the existing directories.
Important: Do not overwrite the wp-content folder, as it contains your themes, plugins, and uploads.
Restore Your Database from a Backup
If you’ve tried the previous methods and still face the Error Establishing A Database Connection, restoring your database from a backup can be an effective solution. How?
Restoring your database from a backup can fix this database error by reverting your database to a previous, error-free state. This is particularly useful if the error was caused by recent changes or corruption.
To continue with this solution, ensure you have a recent and complete database backup. Most hosting providers offer automated backups, or you might have used a backup plugin.
To restore it using phpMyAdmin, go to your hosting control panel and navigate to Files > Backups.

Find Download a Database Backup section and click on your desired database file. It’ll download the database backup to your local machine.

It’s always good to download multiple backups so that if one causes an error, you can use the other one.
After that, navigate to cPanel > Databases > phpMyAdmin.

Select your WordPress database from the left side or click on the Databases tab to select your faulty database. Both methods will take you to your required database.

Click on Import tab.

Choose the backup file from your PC and click Import to start the restoration process.

If you’ve used a backup plugin, access your WordPress dashboard. Go to the backup plugin you used (e.g., UpdraftPlus, BackupBuddy) and follow the plugin’s instructions to restore your database from the backup.
Create a New Database
There are some cases where restoration doesn’t work. In that case, create a new database and import a backup of the database file using phpMyAdmin.
For this, go to cPanel > Databases > Database Wizard.

Write the name of the new database and hit the Next Step button.

Fill in the required details to create a database user for the new database. Then, click Create User.

Next, set privileges for the user. Make sure to provide all the necessary permissions. Finally, click Make Changes button.

Now, go to cPanel > Databases > phpMyAdmin > Databases tab. Click on your database.

Go to the Import tab and choose your database’s backup file that you recently downloaded.

Scroll down to the bottom and hit Import to start the process.

Finally, modify your wp-config.php file to connect your MySQL database to your WordPress site. For this, open File Manager and go to the public_html directory. Locate the wp-config.php file, right-click on it, and select Edit.

A pop-up screen will appear, click Edit on it.

Update your MySQL database name, user, and password. Save the file to make your WordPress dashboard normal.

Check Domain Pointing
Sometimes, switching to a new web hosting provider will also move your site’s files to a new server. In this case, you might encounter this error if your domain is not pointing to the correct database host, preventing the site from accessing data.
So, to ensure that your domain is correctly pointed to your web server, check if the WHOIS and the nameservers in your hosting control panel match.
To check nameservers on Hosted, navigate to Hosted’s dashboard. Scroll down to Account Overview and click the View button next to Manage Domains. Alternatively, you can also use the DNSchecker tool.

On the next screen, you’ll see all your domain names. Click Manage for your desired domain to see its nameservers.

Scroll down to the Nameservers section. If the information matches, your domain points to the correct address and should work properly. Otherwise, update them accordingly, ensuring the nameservers on your web hosting provider and domain registrar control panel are the same.

Important: If you’re hosting your website and domain at Hosted, the nameservers should be automatically set to our nameservers.
Alternatively, point your domain name to Hosted via A record, a type of DNS setting to assign your domain to an IP. Remember, this method only works if you’re using a static address.
To do this, use an online tool (DNS checker) to get your domain name’s A record value. Next, go to your web hosting account and check your server’s IP address.
Then, go to your registrar’s control panel and update the A record value with the IP address from your hosting provider. If you are a Hosted user, find it in the Manage DNS Records.

Why does all this matter? Incorrect domain pointing can prevent your site from connecting to the database, causing errors. Ensuring your domain is correctly configured, will help you maintain a stable connection and avoid disruptions.
Moreover, verifying and updating your domain’s DNS settings helps ensure your WordPress site can consistently connect to its database, keeping your website running smoothly. If issues persist, further troubleshooting may be necessary.
Update Your WordPress Site URL
Changing the WordPress site URL may be necessary if you’ve moved your site to a new domain, changed your hosting provider, or set up a staging environment. In any of these cases, your site’s URL might have changed causing connectivity issues, including the Error Establishing A Database Connection.
To ensure your site URL is correct, you must update it directly in the database. This can resolve issues where WordPress can’t connect to its database because it’s looking at the wrong URL.
To do this, log in to your hosting control panel and open phpMyAdmin. From the list on the left, select your WordPress database. Click on the wpl1_options table. Locate the siteurl and home rows. These settings define your site’s URL.

Click Edit next to siteurl, in the option_value field, enter your correct site URL, and click Go to save the changes.

Repeat this for the home option.
Alternatively, you can execute the following SQL queries to update the URLs directly.
UPDATE wpl1_options SET option_value = 'https://yourwebsite.com' WHERE option_name = 'siteurl';UPDATE wpl1_options SET option_value = 'https://yourwebsite.com' WHERE option_name = 'home';For this, go to phpMyAdmin > SQL tab. Write the above queries and hit Go to run.

Now, check if the database error is resolved. Select your WordPress database again and go to the SQL tab. Write the following queries in the SQL editor and click Go to execute them.
UPDATE wp_options SET option_value = replace(option_value, 'http://www.olddomainname.com', 'http://www.newdomainname.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.olddomainname.com','http://www.newdomainname.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.olddomainname.com', 'http://www.newdomainname.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.olddomainname.com','http://www.newdomainname.com');
Contact Support Teams
Have you tried all the above solutions, but none of them worked? If so, it’s time to contact your hosting provider’s support team, which is available 24/7. They can provide expert assistance, check server logs, and identify any underlying problems that could cause this issue.
Preventive Measures
- Enable Automatic Backups: Set up automatic backups to make sure you always have a recent copy of your website and database. Use plugins like UpdraftPlus or your hosting provider’s backup solutions to schedule regular backups.
- Regularly Optimizing the Database: Optimize your database to keep it running smoothly. Plugins like WP-Optimize can help clean up unnecessary data and improve performance.
- Use Trusted Themes and Plugins: Always use themes and plugins from reputable sources. It reduces the risk of conflicts and ensures better compatibility with WordPress updates.
- Hosting with a Reliable Provider: Choose a reliable hosting provider known for excellent uptime and support. A good host can prevent numerous server-related issues and assist when problems arise.
- Keep WordPress Updated: Regularly update WordPress, along with your themes and plugins. Updates often contain security patches and improvements that help prevent errors.
- Routine Monitoring: Monitor your website’s performance and health regularly. Tools, like Google Analytics and uptime monitoring services can alert you to issues early, allowing you to act before they become major problems.
Implementing these preventive measures can remarkably minimize the likelihood of experiencing the Error Establishing A Database Connection, and maintain a smooth-running WordPress site.
![Expert support with every WordPress hosting plan. [Learn More] Strip Banner Text - Expert support with every WordPress hosting plan. [Learn More]](https://www.hosted.com/articles/wp-content/uploads/2024/07/error_establishing_database_connection_02-1024x229.png)
FAQs
What is the “Error Establishing A Database Connection”?
This error occurs when WordPress can’t connect to your database. It usually shows up as a message on your website.
Why does Error Establishing A Database Connection happen?
Common causes include incorrect database credentials, a corrupted database, server issues, or too many concurrent connections.
How do I check my database credentials?
Verify the database name, username, password, and host in the wp-config.php file.
How can I repair my WordPress database?
Add define(‘WP_ALLOW_REPAIR’, true); to your wp-config.php file and use the repair tool at http://yourwebsite.com/wp-admin/maint/repair.php. Make sure to replace yourwebsite.com with your domain name.
What should I do if my database server is down?
Contact your web hosting provider to check the server status and resolve any issues.
How do I update my WordPress site URL?
Update the siteurl and home values in the wpl1_options table using phpMyAdmin. Or execute the SQL queries that are provided in this article.
How can I replace corrupt core files?
Download a fresh copy of WordPress. Extract the new files and upload them to your web server via FTP. Make sure you exclude the wp-content folder.
How do I check for corrupt plugins or themes?
Deactivate all plugins and themes, then reactivate them singly to pinpoint the problematic ones.
How do I restore my database from a backup?
Use phpMyAdmin or a backup plugin to restore your database from a recent backup file.
What preventive actions can I take to avoid this error?
Enable automatic backups, regularly optimize your database, use trusted themes and plugins, keep everything updated, and monitor your site regularly.
Other Related Tutorials & Blogs:
– 403 Forbidden Error Explained: Easy Fixes for Your Website
– How To Fix NET::ERR_CERT_AUTHORITY_INVALID Error
– How To Fix ERR_CACHE_MISS in Google Chrome
– WordPress Recovery Mode: Everything You Need to Know
– Troubleshooting Guide: Fix Common WordPress Performance Issues
