We are a team of results-driven creative geniuses at PMGS Digital Agency that are enthusiastic about expanding your business and have the skills to do it.
How to fix Error Establishing a Database Connection on WordPress?
Are you experiencing errors establishing a database connection popping up on your WordPress (WP) website?
This could be a serious issue, making the users inaccessible to the site. This often occurs when WP is not able to connect to the database. There are various other issues that will come into play, which make it difficult for a beginner to troubleshoot and solve these problems.
This article will tell you how to fix these errors easily.
Why does Error Establishing a Database Connection occur?
An error establishing a database connection problem will be caused by false input of settings, a damaged database, or a database that does not respond.
Primary contents and contents from other websites are stored using a database on WP, which is more like a CMS (Content Management System). And it connects every site visitor’s details to the database. The information below is required in order to connect the WP site to a database:
- Database Name
- Database Username
- Database Password
- Database Server
These files are saved on your WP as wp-config.php, as we have mentioned in our previous posts.
If any of the above information has any mistakes, then this error will pop up and will not connect the database to your WP. Sometimes credentials are not the only issue. If the database server is down, this will be the error you will be notified of.
Let us see the possible areas that cause this error.
Check the database credentials of your WordPress.
If you recently switched your hosting provider, then chances are high that your credentials would be causing the error. Your WP credentials will be saved in your wp-config.php and this will most likely have the old credentials. And now you need to edit and update it with the new credentials of your new hosting provider.
You can see the below lines in your WP file.
Double check if the name, username, password, and database host are correct.
If you are unsure about the information to be filled in, you can cross-check it with your WordPress hosting account dashboard, by logging in and going to MySQL databases, which are under the database section.
In this article, we will show the steps to follow Bluehost, but the steps are all the same in all hosting control panels.
This will guide you to the hosting dashboard, which will show your database username and password.
And, under that, you will see the database users and the link through which you can change the user password.
Check the information of the database host
If you are sure about the name, username, and password you have given, then this is the next thing you need to look for. That is to check the database host information.
The majority of the WP hosting providers use localhost as your database host. Yet, certain WP companies use dedicated servers to host the database, and if that is the case, your hosting provider will be something else and not localhost. To confirm this, you will have get in touch with the WP hosting company to ensure this detail.
Repair WordPress Database
If your wp-admin displays a different error like ‘’One or more database tables are unavailable. The database may need to be repaired” then the database has to be repaired.
This can be done by adding the following line in your own wp-config.php file. And if you have done this, then you can have a look at your settings by visiting the page at http://www.website.com/wp-admin/maint/repair.php
Also, remember that you do not have to be logged in to access the database repair page. And don’t forget to remove this code from your wo-config.php after repairing and optimising your database without fail.
Check if your database server is down.
If you still have an error popping up that makes it impossible to connect your WP to your database, then the next area you need to check is the database server, which is also called MySQL.
This often occurs due to high website traffic, where if the website visitors are rapidly greater than the load your server can take in.
This issue might bring a delay in loading time to the users and sometimes even show out the error to some users. At this point, the next best move would be to go to your hosting provider’s website’s live chat option and ask them if your MySQL server is responsive. But if you have more sites which run on the same server, then you can check if they are running or if it is the SQL server which is down.
Go to phpMyAdmin and connect to the database in case you do not have any other site on the same host to get this checked. And if you were able to connect, the next step is to open a new file named testconnection.php and paste the following code below to verify if your database has enough permissions.
Do not forget to replace the username and password. Then you need to upload this file to your website and access it through a web browser!
If this worked and it connected, then it means the permission you have is sufficient and the issue is in some other area. You need to go to wp-config and make sure everything is in order and proofread to avoid any types.
Other solutions that worked for users
If none of the above-mentioned methods worked to troubleshoot this error on your WP website, then you need to try the additional tips mentioned below.
Update WordPress site URL
You can update your site URL via your hosting account dashboard, access phpMyAdmin, and select your WordPress database.
Then select the SQL menu as displayed above and enter the below mentioned MySQL query.
Rebooting the Web Server
If you have a dedicated server, local server, or a virtual private server (VPS), then you can try rebooting their servers. This will most probably fix the issue or solve the temporary glitches that caused this error.
If you think this article was useful to you, then stay tuned with us and subscribe to receive our blogs. If you wish to stay connected with us on social media, you can find us on Facebook, Instagram and LinkedIn