So, your website is down, and is just showing this error message “Error Establishing a Database Connection”
In most cases, your website content isn’t gone or missing, it’s just a configuration issue that can usually be resolved quickly.
Follow the steps below to get your database reconnected and your website running smoothly.
Your WordPress Website is generally comprised of two parts; the files, and the database. The files contain the code which runs the software of your website. It’s like your site’s operating system. (media like images are also stored as files) The MySQL Database, on the other hand, is your own personal storage locker for your website content. It stores everything from user details, plugin settings, orders to pages, layouts, and widgets.
Every single piece of data that you place on your website is referenced in the MySQL Database. Simply put, WordPress needs to be able to connect to the MySQL database to retrieve the data that it needs to display on the screen.
Basically, this error message means that, for some reason, WordPress cannot find and connect to the its database.
This is where you encounter the problem “Error establishing a database connection”. Next, we’ll explore the most common reasons WordPress cannot connect to the database.
First, make sure that you are getting the same error both on the front end of the site and on the back end of the site. The front end of the site is what the user interacts with (like https://yoursite.com) and the back end of the site is what the developer/admin interacts with. (usually https://yoursite.com/wp-admin but sometimes this admin address is changed from this default for security reasons).
If the error is not showing, or different on the back end of the site (wp-admin) then you may only need to repair your database. Follow the instructions in Step 1 to repair the database. If the error is the same on both the front end and back end of the site, then proceed to Step 2.
This file is found by accessing your websites files on your hosting servers. Usually this is done by either logging in to your Control Panel (cPanel) from your hosting provider, then using the File Manager tool, or accessing the server files directly via an FTP (File Transfer Protocol) Client.
An FTP Client is an app you install on your computer to upload, download and manage the files on your server. A commonly used free FTP client is FileZilla.
Once you have accessed your sites files, locate the file named wp-config.php. This should be in the “root” or “parent” folder where your website resides. (it’s in the main folder, not a subfolder) You may have to scroll down through the files to find it. (If you see folders like wp-admin, wp-content etc. then you’re in the right place, just scroll down).
Once you find the wp-config.php file, it’s wise to make a backup copy of the file. You can either make the copy on the server, or on your local computer. Once you’ve created the backup, then edit the file. The File Manager tool in your Control Panel has a built-in editor, but if you’re using an FTP client, you must first download the file to your computer and open the downloaded file using a text editor, such as Notepad++. Once the file is open in the text editor, scroll down to the very bottom of the text until you see ‘That’s all, stop editing! Happy blogging’. Start a new line after this line and type or copy the following text:
Save the file and then if necessary, upload it using the FTP client. Overwrite the already existing wp-config file. (As long as you have your backup copy saved) This will allow WordPress to attempt to repair corrupted files within the database. Once the file has been uploaded, go to http://www.yoursite.com/wp-admin/maint/repair.php. Just put the domain name of your website where “yoursite.com” is in this example. Then click Repair and Optimize Database. Once this is done, check to see if the error is gone. If it is still not working, then please proceed to Step 2.
Note: Once this has been completed, remove the command ‘define(‘WP_ALLOW_REPAIR’, true);’ from your wp-config.php file. Then save it and upload it again.
Check the information located in your WP-Config.php file. (See step 1 for how to access your wp-config file) You need to verify that the database name, database username, database password and host name is correct. Not all hosting providers use localhost for the DB_Host value. If you aren’t sure what these credentials should be, you should check with your web hosting provider to ensure that you have the correct information. In the wp-config.php file it will look something like this:
Sometimes these values can be changed by a malware infection, or to an incorrectly executed site migration, or perhaps by a well-meaning but inexperienced web developer.
Once you have double checked that these values are correct, you will need to save the wp-config.php file (and reupload it to the server again if you’re using an FTP client). Again, you should always keep a backup copy of any file you change, before overwriting the existing file.
Once the file has been uploaded, check the connection again by refreshing your website in your browser. If the error “Error Establishing a Database Connection” still displays, move on to Step 3.
This issue is more common when running WordPress on a local server (like your own computer). The IP will vary by hosting provider, just like localhost does. Make sure you check with your hosting provider to ensure that you have the correct IP. Once you have the correct IP, change the data ‘localhost’ in the example above to the servers IP address. Once you have updated this information, save the file and upload it to via the FTP client, overwriting the existing file.
If after following these steps you are still receiving the error, then there may be something wrong on the server end. Sometimes if a WordPress site becomes overloaded with traffic, it can cause MySQL to shut down, causing this error to show (Error Establishing a Database Connection). Usually it reboots right away, and the site works again after a minute or so, but sometimes it will need to be manually rebooting by your hosting provider.
Does this seem like too much of a headache for you? We’re here to help! Our team of WordPress experts can solve any WordPress website issue within minutes, ensuring your website is available for all your users. Click here to learn more about our Service plans to ensure that your site is bomb-proof and running smoothly and securely 24/7.
WBOC.com DelmarvaLife Media Kit eats + drinks Outdoors Delmarva WBOC Classifieds MD Digital Political Ad Disclosures