How to Fix Error Establishing a Database Connection? (5 Quick Fixes)

WordPress is the most popular CMS (Content Management System) for creating and managing Stunning websites and blogs. Thanks to its lower learning curve nature and full of features that makes it is the ultimate platform to create any type of website for anyone.

But what if you have created a WordPress site and when you try to access your webpage, instead of showing the page contents it displays an error message “Error establishing a database connection?”

You don’t like to see such things right, therefore, in this post, we are going to let you know what this error happens and How you can fix it. This ultimate guide will be very helpful for all WordPress users from beginners to Advanced WordPress developers. So stay tuned and keep reading till the end.



How to fix an error establishing a database connection message

Let’s go over each cause one and one and discuss the various steps we can take to fix the error.

1. Incorrect Login and Password

First of all, check whether the login and password are written correctly in the wp-config.php file as this file is perhaps the most important file in the entire WordPress installation process. Here you can set the parameters for WordPress and connect to the database. If you changed your root password or the database password, then you will need to change this file too.

FTP File Manager error establishing database connection
FTP File Manager error establishing a database connection
  • Open the FTP file manager (for example, FileZilla) and connect to the server of your hosting using the login, password, and server name you received when registering. This information you will be able to find on your hosting control panel in the FTP section.
  • Find the wp-config.php file which is located in the root WordPress directory, download it to your local drive, and then open it in Notepad or any code editor like Sublime, VS Code, Brackets, etc.
  • Find the following lines: define (‘DB_NAME’, ‘database-name’); define (‘DB_USER’, ‘database-username’); now define (‘DB_PASSWORD’, ‘database-password’); define (‘DB_HOST’, ‘localhost’); check whether the information is correct. You can find the database name, login, and password in the hosting control panel.
  • Save the changes and upload the file to the server, applying its replacement.
  • Try to open the website again.
wp-config.php wordpress directory
wp-config.php WordPress directory

Remember that the ‘DB_HOST‘ value will not always be localhost. Depending on the hosting, it can be different. For some hosting services, this is localhost. Other values ​​you can find with your hosting provider.

If there are no errors in this file (check for typos), then most likely something is wrong with the server, or the database is corrupted.

2. Corrupted Database

Database recovery

To restore the database using WordPress, you need to take several steps. This method does not require special skills and will restore the database very easily.

database recovery
Database Recovery
  • Connect to the server through the FTP file manager.
  • Download the wp-config.php file and open it in Notepad or any other code editor.
  • In the last line, type the following code pattern: define (‘WP_ALLOW_REPAIR’, true);
  • Save the changes, close the file, and upload it to the server. If necessary, confirm overwriting the updated wp-config.php file.
repair database wordpress
Repair Database WordPress

To perform the next step, in the address bar of your browser type the following address: ‘site-name.com/wp-admin/maint/repair.php’, where site-name.com is your site address. As a result, you will see a screen with two possible options: “Repair database” or “Repair and optimize the database.” Choose one of the options, and wait a bit while WordPress completes the operation.


Note: After restoring the database, be sure to open the wp-config.php file again and delete the line with the code that you added there. Otherwise, you risk giving criminals full access to your database and losing control of the site.


3. Overwriting The Database From The Backup To The Last Working Version

If restoring the database and fixing the login information resolve the problem, you can continue working on the site in normal mode. Otherwise, possibly, the error occurs because of the damaged database.

It will be necessary to restore it from a Database manager like PhpMyAdmin or Adminer, overwriting the database from the previously saved working backup.

Before proceeding with the recovery procedure, make a backup of the current files to avoid data loss. Be careful with the actions of the database manager, because in this panel you directly work with the service tables of the database.

  • Go to Adminer Dashboard using the login and password provided by the hosting provider when registering.
  • You can create a backup of the current database by clicking the export button.
Error Establishing a Database Connection
Error Establishing a Database Connection
  • In the left pane, you will see your database with its tables. In the work area, select the “Import” tab.
Error Establishing a Database Connection
Error Establishing a Database Connection
  • click the “Choose File” button and find the file of the previously made backup.
  • Click OK — all the other data does not need to be changed.

4. The Database Server is Not Responding

You cannot change the situation yourself. So, you need to contact the server hosting support team and try to figure out why the server is not responding. Most providers try to fix the failures as soon as possible.

5. You Reached The Connection Limit

Most lower-end hosting service plans have a connection limit or have really small disk space provided to you. To expand it, you would probably have to buy a more expensive plan and spend more money. It is always advisable to not just check the price but also check the features and server resources that you are getting for your money.

WordPress database errors can be frustrating. We are sure after reading our ways you will be able to resolve the issue with ease.

Error establishing a database connection is quite a common error especially when you are a beginner. We hope that our tutorial helped you to fix it.

If you have faced this issue and fixed it using any other method, that is not mentioned here, please comment below and share it with us.


Error establishing a database connection Chrome Fix

Let us see what efforts can be made to fix the Error establishing a database connection in Chrome from the user end.

1. Update your Google Chrome extensions

Sometimes, an outdated extension that you have installed on your Chrome browser triggers this error. So, you need to update your extensions with the latest version available. To do so, follow the steps given below:

  • Open your Chrome browser and navigate through the three vertical dots located at the top right corner. Click on it and select the More Tools option > Extensions.
Error establishing a database connection chrome Fix
Error establishing a database connection Chrome Fix
  • On the extensions page, toggle on Developer mode and select Update
Error establishing a database connection chrome Fix
Error establishing a database connection Chrome Fix

2. Try Disabling the extensions

If the error persists and the above-mentioned method does not work, you can try fixing this issue by disabling all the installed extensions. If the problem is fixed, then examine each plugin one by one and delete the faulty one.

Disabling Chrome extensions
Disabling Chrome extensions

3. Try clearing your browsing history and cookies

You can also try clearing your browsing history and cookies. Sometimes it works in fixing errors and establishing a database connection.

  • Open your Chrome browser and navigate through the three vertical dots located at the top right corner. Click on it and select the More Tools option > Clear Browsing Data.
Clearing browsing data on chrome
Clearing Browsing Data on Chrome
  • On the Clear browsing data page, select the Time range and click on the Clear data button.
Clearing browsing data on chrome
Clearing Browsing Data on Chrome

4. Update your Chrome browser

Sometimes, an outdated version of the Chrome browser can also be the main reason that triggers errors establishing a database connection issue. So, you must check whether you have the latest version of Chrome installed or not. To do this, follow the simple steps given below:

  • Open your Chrome browser and navigate through the three vertical dots located at the top right corner. Click on it and select Settings.
Google chrome settings
Google Chrome Settings
  • Now select About Chrome and the browser will start checking for updates.
Google chrome update
Google Chrome Update

Now, if you have attempted all the possible solutions to fix the error establishing a database connection issue and yet are not able to overcome this problem. The only thing left for you is to contact your web hosting support for further assistance.


What is an error establishing a database connection error?

WordPress uses two main components in its work: PHP and MySQL. PHP is responsible for the functionality of your site, and MySQL stores all the data related to your site including pages, posts, plugins, widgets, etc.

When you enter the name of a site in the address bar, PHP establishes the connection to the database and extracts the content of the requested page from it. When PHP cannot connect to MySQL for some reason, there is no data to display on the page, and, instead of the content, the browser displays an Error establishing a database connection to WordPress. Read about some other common errors (404, 403, 502, 504)  you might come across.

Here is an article about the new PHP 8 and its improvements over its predecessors


Causes for error establishing a database connection error:

  • Incorrect login and password to connect to the database. This information is provided by your hosting provider and is written in the wp-config.php file located in the root folder of your website.

It happens when you fill in the incorrect login data, or when the registration info changes and it wasn’t corrected in the file.

  • Corrupted database. Unsuccessful settings, incorrect plug-ins, and dropped connections when transferring data to the database could damage the database. In this case, you cannot access it properly.
  • The server where the database is located is not responding. The server may not respond to requests if it is disabled or is out of service. Usually, it is caused by the hosting provider’s technical issues.
  • The connection limit has been reached. Usually, the hosting company does not want the clients to reload the shared database and set a limit on the number of connections from one client, for example, 8.

When your site is visited by many people at the same time, the number of connections will be reached and you will see an error message.

WPOven provides you with managed VPS WordPress hosting with every plan that has FREE daily malware scanning and cleanup, FREE themes and plugins, and FREE WordPress Dev & Server support for starters.

For each reason, there is a solution. Let’s see how it is possible to fix the error depending on the reason why it was caused.


Summary

From the above post, you must have noticed that there is quite a limited solution available to fix errors establishing a database connection error. The most predominant cause for triggering this error is the incorrect login and password in the wp-config.php file.

So it’s better you start with reviewing your login credentials first and then go for other possible solutions. However, if you don’t want it to happen in the future you must choose Quality web hosting just like WPOven(well-optimized for WordPress sites) and Have regular backups.

By the way, do you have ever come across this error establishing a database connection message on your screen? If yes, do let us know how you can fix this problem in the comment section below.


Frequently Asked Questions

How do I fix an Error establishing a database connection?

You can easily fix errors establishing a database connection issue by following these 5 simple solutions:
1. Incorrect login and password
2. Corrupted database
3. The database server is not responding
4. You reached the connection limit
5. Check out your Chrome browser

How do I fix an Error establishing a database connection in Chrome?

Follow these easy steps to fix the error establishing a database connection in Chrome:
1. try accessing the same website on an alternate browser to check whether the Chrome browser is responsible for the error.
2. Update your Chrome extensions
3. Try disabling the installed Chrome extensions.
4. Try clearing your browsing data
5. Update your Chrome browser to the latest version available

What does it mean when it says Error establishing a database connection?

When you enter the name of a site in the address bar, PHP establishes the connection to the database and extracts the content of the requested page from it. When PHP cannot connect to MySQL for some reason, there is no data to display on the page, and, instead of the content. It means, your website files couldn’t able to connect with the database.


Leave a Reply

Your email address will not be published. Required fields are marked *