Do you have a problem of ‘Error establishing a database connection’ in your wordpress website? This could be dangerous for your site because it will make your website inaccessible for the users.
Most website owners see this error when wordpress could not build a connection with the database. There could be many things that can affect your wordpress connection making it difficult to troubleshoot the problems.
Here, we are going to describe how to fix the error establishing a database connection in WordPress.
Why “Establishing a Database Connection” error occur in WordPress?
This is one of the most common errors that owners of WordPress websites face. Cude Design – Surrey said ‘the error of “establishing a database connection” occurs due to wrong information in wordpress settings, corrupt database, or non-responding database server.’.
So what is a database? Database is software which stores, organizes and retrieves data. WordPress uses this software to store content and other website data. This connects your website to the database when a user visits your website to read content.
WordPress needs the four types of information to connect with the database:
- Database name
- Database server
Your wordpress website contains the above information in a file called wp-config.php. If you provide any incorrect information about these items, wordpress would not be able to connect to your data server and ultimately you’ll see the “Error establishing a database connection”.
This is the most common error in wordpress and many owners have to face this at the initial stage.
Apart from this, this error could be due to some other reasons as well. Let’s start how to fix this issue.
1. Verify Your Database Credentials
Incorrect database credentials could be the main reason for database connection error. It mostly happened with those who move their wordpress website to a new host. If you have done the same, you may face this problem.
As described earlier, your credentials are stored in the wp-confi.php file. This file contains all important information and settings including database information. You have to make sure that you have put correct information of username, password and database host for the database connection.
You can easily check this information from your wordpress dashboard. Simply log in to your account and click on MySQL database in the database section. After confirming your name, username and password, you can edit the information in the wp-config.php file.
After performing these actions, go to your site to check if the problems have been resolved or not.
2. Check Database Host Information
If you think that your information is correct and still facing ‘Error establishing a database connection’ you need to check the database host information. Many hosting companies use a local host as your database host while some good hosting companies use separate servers to host the database. In this situation, your database information will not be local and you have to contact your WordPress hosting company to confirm your database host information.
3. Repair WordPress Database
Sometimes you see a different error on your wordpress dashboard like “One or more database tables are unavailable”. This error means you need to repair the database. For this, you have to add the given line in your wp-config.php.
Make sure you have added this line before ‘That’s all, stop editing! Happy blogging’ line wp-config.php. After adding this line, see the setting by visiting www.yoursite.com/wp-admin/maint/repair.php
4. Check Your Database Server
Another reason for ‘Error establishing a database connection’ could be due to your database server. If everything is OK then your database server (MSQL server) is down.
It happens when a server has heavy traffic and fails to handle the heavy load of traffic especially when you are using shared hosting.
In this situation, your site will load slowly and even show errors to some users. At that time you need to contact your hosting provider and ask them to resolve the issue. If you are running more than one site on the same server, you should check other sites to confirm whether it is a problem of hosting or something else. If you have a single site, then go to the hosting dashboard and try to reach phpMyAdmin and connect the database.
Other Ways to Solve This Problem
There are some additional ways to resolve this problem if the previous mentioned methods are not working. These steps can help you to resolve the ‘Error establishing a database connection’ on your website.
1. Update WordPress Site URL
Go to your phpMyAdmin and try to update your wordpress site URL. You can do this simply by accessing your hosting account dashboard.
Never forget to provide your own site URL and change wp_options to your own table name as you may have changed the wordpress table prefix.
2. Rebooting Web Server
The website owners who are using dedicated servers, local servers or VPS (virtual private servers) should try to reboot the servers. Your database server and web may restart and the errors will be removed.
3. Ask for help
The final solution is “ask for help” if everything fails and you can’t resolve the issue. For this purpose, you may need to contact your web hosting company. All good companies will assist you to fix the database connection error.
You can get help from web designers or experts who can help you to fix this issue at a reasonable price. They have expertise to resolve the issue and your site will work correctly soon.
We hope you will get help from this article to fix the error establishing a database connection in WordPress. Still if you think we have missed anything, you can ask in the comment section.