One of the most frequent issues that WordPress users can get is “trouble establishing a database connection.” It and the “white screen of death” are closely related (WSOD). Your entire website crashes due to this problem since your website is no longer in communication with or has access to your WordPress database.
As this problem can potentially impact your sales, traffic, and analytics negatively, you should fix it right now. Any long-term harm can be avoided, and this issue can be fixed easily. To fix this typical problem, simply adhere to the instructions provided in this tutorial.
Your MySQL database houses all of the data on your WordPress website, including post data, page data, metadata, plugin settings, and login data. Media content like photos and your theme/plugin/core files like index.php, wp-login.php, etc., are the only data types not saved there. When a user accesses your website, PHP runs the page’s code, requests the data from the database, and then presents the results to the user in their browser.
As seen below, you will face an “error establishing a database connection” warning if this isn’t functioning correctly. Due to a broken connection, you can collect no data from rendering the page, leaving the entire page blank. It will destroy your website’s front end and make it impossible for you to get into your WordPress dashboard. Visitors might not immediately notice this issue on the front end, though. That’s because your website is probably still using its cache to serve visitors until it expires.
Mass Users Password Reset Pro Plugin for WordPress
Reset Multiple User’s Password In Just One Click
PHP and MySQL are the two significant pieces of technology that WordPress employs to give you all of its great features. PHP is used to write the essential WordPress files. Database technology is MySQL. WordPress stores all of your website’s content in a MySQL database. It contains your pages and articles and the smaller components like your site’s title, widgets’ layouts, colour preferences, etc. The MySQL database essentially serves as the repository for any information related to your website, no matter how small it is.
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. It is where the mistake is made. An error is generated when WordPress’s PHP commands cannot access the data in the database for any reason. WordPress can only say in that situation, “Error establishing a database connection,” since it essentially has no idea what to do after that. Such an error can occur for the reasons listed below:
It could be caused by a malicious plugin causing internal database issues, a hacker attack, a theme going wrong, and many other things.
Among other things, a bad update can corrupt the core WordPress files. It can refer to issues like unsuccessful plugins, themes, or even core WordPress software updates.
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 be offline for any reason.
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.
This problem is beneficial, yet it is still a problem. A significant increase in traffic may cause your database to become unresponsive.
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. Find out from your host provider whether the database server is up and operating without any issues and whether there isn’t a current surge in activities or traffic on the server. Most of the time, if you let them know what kind of issue you’re experiencing, they will tell you precisely 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.
To connect to the database, WordPress uses a specific username and password. 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 unusual situations. In other words, the access credentials occasionally change, even though they shouldn’t. A “Error establishing a database connection” occurs when access credentials are invalid. The fixup can be done in the “wp-config.php” file. We’re specifically referring to the following lines:
They contain all the information required for WordPress to access the database. There won’t be any connection if any of these settings are off. Inform your web host of these details and ask whether they are correct, if the details are inaccurate, they will simply provide you with feedback and amend the file accordingly.
Follow the steps below to check if the plugins or theme files are corrupted:
FTP access to your host is required. You must have a special login ID and password for your FTP account to connect. If you don’t understand what/where those are, the most straightforward approach to find them is to read through the emails you received from the web host when you originally signed up. Alternatively, you can request that the live chat support professional provide you with those details.
Connect to the server and browse to the Wp root folder after you have these. It’s commonly called “public html” or “www,” and you may already be in it if you’ve established an FTP connection.
Enter “wp-content” and rename the “plugins” folder to a different name (anything other than “plugins”). Return to your website and look to see whether the error remains. If otherwise, you now know a plugin caused it. Return to FTP and rename the folder “plugins” again. Modify the folder name of the various plugins one at a time. The simplest method is to put an underscore at the end: “_”.
Return to your website to check when the mistake occurs or disappears. You’ve located the culprit after reducing it to a single plugin. Delete it or look online to see whether the solution is documented. If the error persists after renaming the “plugins” folder, repeat the procedure with the “themes” folder. If that doesn’t work, rename both files to “plugins” and “themes” again. Something else is causing the error.
The WordPress database is a rather sophisticated entity, with many small cogs that must all operate properly together to avoid problems. You will observe the error establishing a database connection when something is out of place.
The first thing to do is to your WordPress dashboard. Skip this step if you encounter the same fundamental error: “trouble establishing a database connection.”
Second, if you see something else, pay close attention to what WordPress recommends you do. WordPress has increased its problem-solving options in recent editions, so you might find some valuable tips there. Another possibility is that you will receive a warning, “One or maybe more database tables are unavailable […].” It implies that you must “fix” the database. It is fairly straightforward. First, reconnect to your site using FTP. Go to WordPress root and download the “wp-config.php” file to your desktop. In the notepad, add one further line at the end (just before “That’s all, finish editing”).
|define(true, ‘WP ALLOW REPAIR’);|
Now, upload the file to your website (through FTP), overwriting the previous version.
For various causes, the core WordPress assets can become corrupted. Perhaps there was a hacking effort on your site, you accidentally modified certain files, or a malicious plugin caused the modification. Whatever the case, you can still restore WordPress’s default, native files. The simplest approach is to download a fresh copy of WordPress from WordPress.org and replace the one you already have.
Go here and save the most recent package to your desktop. Unpack. Examine the uncompressed archive and remove the “wp-content” folder. Connect your site through FTP, navigate to the WordPress root, and upload your new WordPress files. Replace all prior files. Return to your site to see the effect after the upload is complete.
As you can see, there are numerous approaches to resolving the “problem establishing a database connection” error with WordPress. The most common problem is invalid credentials in the wp-config.php file. The greatest place to start is by double-checking those. Downtime is the last factor you want for your website. Hopefully, one of the actions outlined above assisted you in getting your site back on track. Remember, if necessary, you can always recover your site from a backup.