“Error establishing a database connection” is one of the common errors we have encountered while surfing different websites over the internet. No matter how many times you refresh, you’re unable to access the website.
We will try to guide the solution by collecting all the solutions to one place.
How WordPress works and how error occurs?
All the information that makes up our website is stored in a MySQL database. The information is stored and retrieved from the database in WordPress using PHP.
PHP code is used to retrieve every bit of information required to build up the page. There is a PHP query to access the post title, author name, published date and so on.
“ERROR ESTABLISHING A DATABASE CONNECTION” simply means PHP code is not connecting with MySQL database to extract the information it needs to develop the pages. If the connection to the database cannot be established, there is no way to know what to display as no information about the website is available.
The possible reason for the error
There could be various reasons that result in the error.
Following are the possible reasons:
- Database login credentials are incorrect: This could be one of the possible reasons for this error. The WordPress website uses different login information to connect with the MySQL database.
- The database is corrupted: The corrupted databases may be another reason for causing database error. The database may get corrupted with moving themes plugins parts and users by deleting and installing them. This is occurred by missing or individually corrupted table, or if some information was deleted accidentally. Your WordPress can have corrupted files which is due to hackers.
- Issues with your database server: You may have issues with your database server. This is the usual issues of Shared hosting as it has a lot of users on save servers. The database can be overloaded from traffic or unresponsive from too many concurrent connections on the web host end.
How to Fix the Error Establishing a Database Connection
Before proceeding for the troubleshooting, it is recommended to take the database backup.
Fixing QuickError Establishing a Database Connection in WordPress:
Checking Database login credentials
The wrong login credential is the most common reason for database connection error. The connection details of your WordPress website are stored in the wp-config.php file which is located at the root folder of the WordPress site. It contains four elements database name, database username, database password, and database hostname. Make sure all the details are correct.
Repair Corrupt Database
It might be possible that MySQL database has become corrupt, although not very often, as over time hundreds of tables are constantly added/removed by new plugins and themes. You might get a message such as ‘“One or more database table are unavailable, the database may need to be repaired” .WordPress actually has a database repair mode which you can initiate. Simply add the following to the bottom of your wp-config.php file.
Fixing Corrupted Files
Another possible reason you might be seeing this message is that your website files may have been corrupted. This has also occurred while transferring files via FTP by a hacker gaining access to your site or an issue with your web host. You can easily fix this problem.
You are basically going to replace the core version of WordPress on your site. You aren’t touching your plugins, themes, or media, just the WordPress installation itself. To do this, you will need to download a fresh copy of WordPress from WordPress.org.
Issues With Your Database Server
If none of the above has helped resolve your issue, then we recommend asking your hosting provider as it could be an issue with your database server.
For example, if there are too many concurrent connections to your database at once, it could generate the error. This is because a lot of hosts have limits on their servers on how many connections are allowed at once.