It seems you have encountered, or might have seen somewhere, an “Error Establishing a Database Connection” message on WordPress site.
This error is one of the most notorious and fatal errors in WordPress, as it makes your website inaccessible to users. It triggers when WordPress is unable to establish a connection with the Database.
Since this error can occur due to a variety of reasons, it might not be an easy task for beginners to figure out the exact cause and fix it.
Therefore, we have come up with a comprehensive post on How to Fix Error Establishing a Database Connection on your WordPress Site. We also mention the possible causes that trigger it, along with its true meaning.
So, stay tuned and keep reading till the end.
How to fix an error establishing a database connection message
Let’s check out each cause one by one and also at the same time discuss the steps to fix the error.
1. Incorrect Login and Password
One of the most common mistakes that anyone could make is entering Login credentials incorrectly. Therefore, you also need to check if the login credentials are correctly mentioned in the Wp-config.php file.
Since this file is perhaps the most important for the entire WordPress installation process. Here is how you can check and set the parameters for WordPress and correct them in the database.
However, if you have changed your root password or the database password, then you will need to change this particular file too.
- Open the FTP file client i.e. FileZilla and connect to the server using the login, password, and server name you received when registering with the web hosting service. (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.
Note: 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. Repair Corrupted WordPress 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.
- 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.
To perform the next step, in your browser’s address bar, type the following address: ‘site-name.com/wp-admin/maint/repair.php’, where site-name.com is your website address.
As a result, you will see a screen with two 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 normally. Otherwise, possibly, the error occurs because of the damaged database.
Restoring it from a Database manager like PhpMyAdmin or Adminer will be necessary, overwriting the database from the previously saved working backup.
Before proceeding with the recovery procedure, backup 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.
- In the left pane, you will see your database with its tables. In the work area, select the “Import” tab.
- 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 do not have control over sever but you can contact the server hosting support team and try to figure out why the server is not responding. Most providers try to fix the server failures as soon as it happens.
Sometimes, what happens is that the server is overloaded due to too much web traffic, especially in case of shared hosting.
( This is why it’s always highly recommended to opt for Managed Dedicated hosting for a seamless and smooth experience, especially if you notice a significant increase in your website traffic. It’s a sign that you need to upgrade.)
Your website will become sluggish and page loading time will increase. You might also see an error message on your screen.
In this case, the best thing you can do is to contact your web hosting provider and ask them, if the MySQL server is working properly or not.
On the other hand, if you have other websites hosted on the same server, try to access them and check if they are also affected.
If not, go to your hosting panel or dashboard and try to access phpMyAdmin to connect to the database.
If you can connect to the database, we need to examine if the database user has set the right permissions or not. For this, you need to create a new file name testing.php and add the following lines of code to it.
1 2 3 4 5 6 7 8 |
<?php $link = mysqli_connect('localhost', 'username', 'password'); if (!$link) { die('Could not connect: ' . mysqli_error()); } echo 'Connected successfully'; mysqli_close($link); ?> |
Do not forget to replace the “username” and “password” and upload this file to your website. After that try to access your website again via web browser.
If this script can run successfully, it shows that your user has sufficient permissions. If not, you have to investigate further.
You can check your wp-config.php file again to verify if everything is put correctly or not.
5. You Reached The Connection Limit
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.
6. Change the WordPress Site URL
If none of the above-mentioned methods work for you, you can try changing the WordPress Site URL using phpMyAdmin.
All you have to do is access phpMyAdmin from your web host’s dashboard and choose your WordPress database.
Now click on the SQL menu to add the given MySQL query.
1 2 |
UPDATE wp_options SET option_value='YOUR_SITE_URL' WHERE option_name='siteurl' |
Please note that you have to replace the Your_Site_Url with your site URL and wp_options in your table.
7. Restart your Web Server
If your website is hosted on a dedicated server, cloud server, or VPS, you can try restarting your web server.
This might fix any errors that occurred due to temporary glitches.
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.
- On the extensions page, toggle on Developer mode and select Update
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.
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.
- On the Clear browsing data page, select the Time range and click on the Clear data button.
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.
- Now select About Chrome and the browser will start checking for updates.
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.
5. Contact Support
If none of the above mentioned methods work, the only thing left for you is to contact the Web hosting provider and ask for assistance. Web hosting companies generally have a dedicated Support Expert team that will help you troubleshoot the problem, give you the proper guidelines and even they can resolve it.
What is an error establishing a database connection error?
The error establishing a database connection error simply means that the website is unable to establish a connection to a WordPress database, which disallows the page to render.
This is how it happens:
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( mainly happen due to wrong login credentials or a corrupt Database) 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.
You can also check 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 you should 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.
I am a Co-Founder at WPOven INC currently living in Vancouver, Canada. My interests range from Web Development to Product development and Client projects. I am also interested in web development, WordPress, and entrepreneurship.