seeing the terrifying, Error establishing database connection in WordPress or any Website platform
…is what a bad day for a WordPress website owner looks like.
Yes, this error notice appears to be extremely significant. There is only text; there are no design or recognizable WordPress site features.
The first thing you need here is to calm yourself down. We know your heart is beating fast. It has happened to many of us just like you. Be less assured that this issue will be fixed. Keep reading.
Understanding the Issue of “Error Establishing Database Connection” In WordPress
Although we don’t want to be the ones to point out the obvious, the problem is one that occurs when creating a database connection.
What it really means is as follows:
PHP and MySQL are the two major pieces of technology that WordPress employs to give you all of its great features.
. The content of your website is all stored by WordPress in a MySQL database. This covers your pages and articles as well as the smaller components like your site’s title, the way your widgets are laid up, the color options, etc.
The MySQL database essentially houses all of the data about your website, down to the tiniest of details.
Combining the two, WordPress connects to the MySQL database using PHP commands, retrieves the data it needs, and then displays the results on the screen.
This is where the mistake is made. When WordPress’s PHP commands are unable to access the data in the database for any reason, an error is generated. The only thing WordPress can say in that situation is, “Error establishing a database connection,” since it essentially has no idea what to do after that.
Having stated that there may be a number of causes for the problem among the more typical ones:
Incorrect login information: To access the database, WordPress requires a special login and password. WordPress won’t be able to retrieve anything from the database if things have changed for any reason.
Corrupted database: This could be caused by a malicious plugin causing internal database issues, a hacker attack, a theme going wrong, and many other things.
Corrupted WordPress files: Among other things, a failed update can corrupt the core WordPress files. This can refer to issues like unsuccessful plugin, theme, or even core WordPress software updates.
The database server is not running: In certain instances, the database is run on a different machine from the web server, the server that houses the files for your website. Additionally, the separate database server could just be offline for any reason. In certain instances, the database is run on a different machine from the web server, the server that houses the files for your website. Additionally, the separate database server could just be offline for any reason.
Excessive traffic: This problem is beneficial to have, yet it is still a problem. Particularly, a significant increase in traffic may cause your database to become unresponsive. For instance, what if one of your postings went viral and everyone and their dog is now attempting to access it? As a result, some of those visits cannot be handled by the server.
How To Fix “Error Establishing a Database Connection”
We will start by recommending a course of action that is most likely to provide you with a rapid cure for the issue because we respect your time. Then, we’ll delve even further and demonstrate how to carry out every repair manually on your own.
Step 1: Contact Your Web Hosting Company
This is our most top recommended first step. Though it varies on how efficient or responsive your website hosting provider is. In our case, we use Hostinger and Bluehost. They are very supportive and always willing to assist you to resolve this problem.
It is safe to presume that your web host may be at fault if your site was functioning just a moment ago (or a day ago) and isn’t now.
Nowadays, all top-notch hosts provide instant assistance in some manner, typically via live chat.
Start by calling that live chat, stating that you’re having a “problem establishing a database connection” (copy the phrase), and requesting the following information:
- if there isn’t currently a spike in activity or server traffic, and the database server is up and running without any issues.
- If your Webhosting package has expired and your database has been archived.
Most of the time, if you let them know what kind of issue you’re experiencing, they will either let you know exactly what the source is or even solve it for you.
Most importantly, they will inform you of any unusual behavior on the server and whether your database is in good shape.
If they are unwilling to assist you and the problem is not on their end (the server is up and running and there are no traffic spikes), move on to step 2:
Step 2: Verify That Your Plugin and Theme Files Are Not Corrupt
There are a few unfortunate circumstances that could cause your WordPress files to become corrupted.
For instance, what if something collapsed after you upgraded a plugin or theme? Perhaps you connected the website to an outside service? Perhaps you modified some of the files by hand?
You probably know who’s to blame if any of the aforementioned things come to mind. Skip this step if you haven’t done any of those things.
What you can do is as follows:
- Make an FTP connection to your server first. Using the free tool FileZilla, you may accomplish this.
You’ll need your FTP account login and password in order to connect. Searching through the original emails you received from your web host when you first joined up is the simplest approach to find them if you don’t know what or where they are. As an alternative, you can ask the live chat support agent to provide you with those details.
Once you have them, login to the server and go to the root folder for WordPress. Typically, it goes by the names “public Html” or “www,” or you might already be there once the FTP connection has been made.
As a general guideline, if you can see subfolders like “wp-content” and “wp-admin,” you are in the root of WordPress. Example:
- Second, change the “plugins” folder under “wp-content” to something else (anything else, as long as it’s not “plugins”).
- Third: Go back to your site and see if the error is still there.
In the event that it does not, you now understand that a plugin is to blame. Rename the general plugin folder back to “plugins” once more by returning to FTP. Change each plugin’s folder name individually by entering it and doing so. Put an underscore (“_”) at the end for the simplest solution.
Keep checking your website to see whether the error reappears or disappears. You’ve identified the problem once you’ve reduced it to a single plugin. Remove it or search online to see if the solution has been explained.
- Repeat the same steps with the “themes” folder if the error persists after renaming the “plugins” folder.
- Rename both folders back to “plugins” and “themes” if that doesn’t work. Something else is to be blamed for the error.
Proceed to step three if all of the above did not work.
Step 3: Verify That Your Database Has Not Been Corrupted.
The WordPress database is a rather sophisticated system, and many tiny cogs must continue to function flawlessly in order to prevent problems. “Error establishing a database connection”in WordPress or any website appears occasionally when something is out of place.
Go to your WordPress dashboard to do the first check by visiting www.your-website-domain-name.com/wp-admin
- Skip this step if you have the same main issue: “Error Establishing a database connection.”
- Secondly, pay close attention to what WordPress advises you to do if you observe anything else. WordPress has increased the number of problem-solving options in recent editions, so you might find some helpful suggestions there.
Another possibility is that a notification with the opening phrase “One or more database tables are unavailable […]” will appear. This indicates that you must “repair” the database.
Actually, this is fairly easy. First, establish another FTP connection to your website. Download the “wp-config.php” file to your desktop by visiting the WordPress root.
Edit the following file in Notepad and add the following line just before “That’s all, stop editing”:
Reupload the file to your website (through FTP) and replace the previous version.
Visit www.your-website-domain-name.COM/wp-admin/maint/repair.php to begin.
What you ought to observe is this:
Select a button by clicking one. Return to your site and check to see if the error is still present once the automatic repair is finished.
If not, excellent! However, you must still restore the prior version of your “wp-config.php” file. Re-upload the file after removing the newly inserted line.
The following actions in step 4 are taken if the fault persists:
Step 4: Verify and Check Your Database Connection Credentials.
WordPress connects to the database using a certain username and password, as we previously mentioned. These login credentials often don’t alter on their own. However, if you alter anything—your site’s files, the hosting environment, or anything else—you can encounter some peculiar situations. In other words, the access credentials do occasionally change, even though it shouldn’t. Additionally, “error establishing a database connection” occurs when access credentials are invalid.
The fix is made in the “wp-config.php” file. Specifically, we’re referring to these lines:
define('DB_NAME', 'some_db'); define('DB_USER', 'some_username'); define('DB_PASSWORD', 'some_pass'); define('DB_HOST', 'localhost');
They contain all the information required for WordPress to connect to the database. There won’t be any connection if any of these are off.
Simply copy those four lines from the “wp-config.php” file to the clipboard, call your web host support once more, paste those lines into the chat window, and inquire about whether the information is accurate so you may connect to your database.
After reviewing everything, the representative will get back to you with some comments. In the vast majority of cases, they will give you accurate information if anything has changed.
All you have to do is replace the old credentials in your “wp-config.php” file with the new ones.
define('DB_NAME', 'some_db'); /* this is the name of your WordPress database */ define('DB_USER', 'some_username'); define('DB_PASSWORD', 'some_pass'); define('DB_HOST', 'localhost'); /* this is the web address of your database server */
Re-upload the file through FTP to finish.
You can now return to your website and check to see if the error has been repaired.
If not, here is the last step we have for you:
Step 5: Restore WordPress Default Files.
The core WordPress files can become corrupted for a variety of causes, as we’ve already stated. Your website may have been the target of a hacking effort, you may have accidentally edited certain files, or a malicious plugin may have made the change.
Whatever the case, you can still restore WordPress’ native, default files. The simplest approach to do this is to just download a fresh copy of WordPress from WordPress.org and paste it over the current version you are using.
Visit this page to download the most recent package to your desktop. Unpack. Look through the archive that has been unpacked and remove the “wp-content” folder.
Next, establish an FTP connection to your website, navigate to the WordPress root, and upload your new WordPress files. Delete all of the preceding files.
Return back to your site after the upload is complete to observe the results.
This is a last-ditch kind of solution. If this doesn’t work, your only option will be to call your web host’s support line again, explain all you’ve tried, and ask for assistance. By this time, you’ve essentially done everything you can to resolve the problem on your own, so it’s up to the host to do so. After all, aren’t you responsible for paying your hosting bills?
How Can We Prevent This Mistake Error Establishing a Database Connection In WordPress in the Future?
There are two key pieces that you should have in your insurance puzzle to be at least 90% safe, even though there isn’t a 100% fail-proof method to safeguard your website against any error establishing a database connection:
- Excellent hosting: Use only Web hosting companies whose platforms have been modified to function with WordPress. In this manner, you can always rely on qualified assistance and prompt assistance. Not to mention that you will prevent a lot of typical WordPress issues. Here are our suggestions for WordPress hosting ( Bluehost, Hostinger )
- Regular automatic backup: You should always have a functional WordPress backup that you can restore if something goes wrong if you install a straightforward backup plugin like UpdraftPlus (it runs automatically).
This informational resource should be useful. And as usual, don’t hesitate to get in touch with us (or leave a comment) if you’re experiencing trouble with a database connection error.