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

WordPress is the most popular content management system to create websites and blogs. It is very easy to use and allows the creation of powerful resources. But what if you create a website, enter the page, and see that instead of page content your browser displays the message Error establishing a database connection.

In this post, we are going to review why the error happens and the effective ways to fix it. This manual will be useful for all beginning WordPress developers.

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

What is error establishing a database How to Fix Error Establishing a Database Connection? (5 Quick Fixes)
what is error establishing a database connection

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, 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.
Causes of error establishing a database connection How to Fix Error Establishing a Database Connection? (5 Quick Fixes)
Causes for a database connection error

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 dedicated servers with every plan starting at $16.61  per month along with FREE daily malware scanning and cleanup, FREE themes & Plugins, FREE WordPress Dev & Server support for starters.

wordpress security

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

How to fix  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.

How to Fix Error Establishing a Database Connection
How to Fix Error Establishing a Database Connection

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

  1. 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.
  2. 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.
  3. 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.
  4. Save the changes and upload the file to the server, applying its replacement.
  5. Try to open the website again.

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.

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

  1. Connect to the server through the FTP file manager.
  2. Download the wp-config.php file and open it in Notepad or any other code editor.
  3. In the last line, type the following code pattern: define (‘WP_ALLOW_REPAIR’, true);
  4. 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

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.

Overwriting the database from the backup to the last working version

If restoring the database and fixing the login information resolved 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.

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

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.

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 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, which is not mentioned here, please comment below and share with us

Error establishing a database connection chrome Fix

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

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:

  1. 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

2. On the extensions page, toggle on Developer mode and select Update

Error establishing a database connection chrome Fix

Try Disabling the extensions

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

Disabling Chrome extensions

Try clearing your browsing history and cookies

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

  1. 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

2. On the Clear browsing data page, select the Time range and click on the clear data button.

Clearing browsing data on chrome

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 these simple steps given below:

  1. 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

2. Now select About Chrome and the browser will start checking for updates.

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.

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 must start with reviewing your login credentials first and then go for other possible solutions. However, if you won’t like 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 come you can fix this problem in the comment section below.

Frequently Asked Questions

How do I fix Error establishing a database connection?

You can easily fix error 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 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.