If you are a beginner working on WordPress, the most dreadful thing to see on the screen could be a message with no familiar site design, or any other elements, or relevant links, but simply the haunting text in bold which is read as “Error in establishing a database Connection.” But do not worry much as most of these can be fixed. Also, this is quite common, and if you know how to fix it, this can be repaired without losing any of your data. This post contains some information on how to fix this unexpected error.
Understanding The Problem
The first thing to do here is to stop panicking and start understanding the problem. To a layman, the error is self-explanatory and precisely it means that there is a problem or difficulty in establishing the database connection. If you are using WordPress on your website, you must be familiar with the terms like PHP and MySQL, maybe not exactly what they are or what they do but just the terms. This is all about them and the error revolves around these two.
PHP And MySQL
PHP is the programming language used by WordPress. This means all the codes and commands of WordPress are written in this language. On the other hand, MySQL is the database in which all the files and documents of your website are stored. In general, anything written in WordPress will be converted into the codes of PHP and will be saved in MySQL. Similarly, when asked for anything, the command is converted to PHP and will reach the MySQL database to give the information, provided everything is functioning well.
However, at times, the machines, coding language can go nuts and there can be some difficulty in the understanding and analyzing of the PHP commands. Thus making it tough for them to reach the MySQL and provide the requested data. If the PHP commands do not reach the database to provide data, the error text message read as “error in establishing a database connection” pops up on the screen.
Fixing The Problem
After understanding the problem behind the error message, one should also get an idea on how to correct the error and fix the problem. Here are a few steps to consider in order to fix the error.
- Reach out to your web host: the problem, in general, could be resolved upon contacting the web host’s end via a live chat and ask for the issues about database server or spikes in the traffic activity.
- Check your plugins and theme files: This is another reason behind the error. Check for any failed software updates of corrupted theme files and fix them to get rid of the error. To do so navigate to the WordPress root files, rename the plugins and check back.
- Database connection and credentials: At times, there can be a crash because of the corrupted database credentials or the connection.
If the error is a result of a corrupted database, then navigate to the root files and download “wp-config.php” and simply add a command, repair. After doing this upload the file back and overwrite the older version. This should resolve the issue.
Unlike the error in the corrupted database, if the error happens as a result of an error in corrupted database credentials, then the fix should happen to the “wp-config.php” file. If this needs to be fixed, then seeking the advice of your web host support can be a better option. Because this process includes several steps, which can be confusing.
If even after trying all the above options you still see an error, then simply restore your default WordPress files. These files can be corrupted for numerous reasons. So instead of finding reasons, simply download a clean version of WordPress and copy it over by going to the root files. Upload the new files and overwrite the old ones.
Reasons For Error
No one can know the actual reason behind these errors. But experts of WordPress believe that the following can be the reasons behind the error message. They include:
- Server issues: Web server that stores your website files and the one on which your machine works may be different thus popping up database server issues. And this server of the database may run down for diverse unknown reasons, causing the error.
- Corrupted WordPress database or files: Time and often, the system may fail on its software updates. Also, hacker’s attack the internal database or for some unknown reasons mess up with the plugins thus resulting in the file corruption. All of this may result in causing the error in establishing a database connection.
- Incorrect login credentials: At times one may forget their login credentials or again hacker’s act by logging in using wrong user information and password. This will again result in an error message.