Let’s talk about “Error Establishing a Database Connection” error today.
WordPress uses two trendier technologies, PHP and MySQL, to offer excellent database capabilities. MySQL database stores the entire database for your WordPress website, including the pages, posts, site title, layout widgets, and other components.
The “Error Establishing a Database Connection” message panics many WordPress users and they start trying various tricks to solve the same problem. However, there is nothing major to worry about as some smaller steps will help you solve it in no time.
Fixing the problem “Establishing a Database Connection”
WordPress utilizes the following details for establishing a connection to the database:
- Database name
- Database username
- Database password
- Database server
These details are stored in a WordPress file named wp.config.php. If any of the details are somehow altered and incorrect. Due to this WordPress fails to establish a connection to its database server. This may result in the error message “Error Establishing a Database Connection.”
Tip: If your site is hosted on VPS, Dedicated Server or on server instances like Amazon or Digital Ocean, you can try restarting the server. Many times just doing that, will solve the “Error Establishing a Database Connection” error.
If that does not work, then you can try below options:
Fix 1: Check the Database credentials
A common reason behind the occurrence of this error is the incorrect database credential. If you recently changed the host for your website, then that might be a key reason behind the “Error Establishing a Database Connection.” For this, you must visit the wp-config.php file and edit the details in that.
Here are the details that you will see in the wp-config.php file:
/** The database name for the WordPress*/
define( ‘DB_NAME’, ‘database_name’ );
/** Database username for MySQL */
define( ‘DB_USER’, ‘username_put’ );
/** Database password for MySQL*/
define( ‘DB_PASSWORD’, ‘password_put’ );
/** Hostname for MySQL */
define( ‘DB_HOST’, ‘localhost’ );
You need to check whether these details are correct or not. You can tally the details from your hosting account dashboard of WordPress.
1. Log in to the hosting account and move to the MySQL database under the database section.
2. You will be redirected to the hosting dashboard’s database management page. Check for the Database name and the username from this page.
3. Further, you will find the Database users and links for changing user passwords. After confirming the username, passwords, and database name, check for matching these details with the wp-config.php file.
Further, it is time to revisit your website to check if the issue persists or the error is solved.
Fix 2: Connect with your web host provider
Contacting the web host support service is also a recommended option. There might be the case when your entire website was working a few minutes ago, and then everything suddenly stops. In that instance, your web host provider is at fault.
Try contacting your web host provider via live chat (if available) to help resolve the “Error Establishing a Database Connection.” Ask them the relevant questions regarding the issue. Mostly, being a little brief about the issue and just telling them that the error occurred will let them know the exact cause for the issue and help you fix the same.
They will also understand and tell you whether the database is working well or any suspicious activity that might have caused the “Error Establishing a Database Connection.”
However, if the issue is still not solved and the issue is at your end, then you must try following the other available tricks to resolve the same.
Fix 3: Check if the Plugin or Theme files are corrupt:
The “Error Establishing a Database Connection” issue might also be the case when you have updated the theme or the plugin. The entire thing might also collapse after that. Also, check if you have hand-edited any files recently or made any recent changes.
Here are the steps which might help you resolve the error:
1. Connect your host via FTP. The credential for your FTP account might be available in some initial emails that the web host provider sent you, and you first signed up with them. You can also ask for the help of a live chat support representative to get access to the login credentials for your FTP account.
2. Next, connect to the server and then navigate to the WordPress root folder. It is generally called ‘www’ or ‘public_html.’ The root contains the files with names like ‘wp-content or ‘wp-admin.
3. Next, go to ‘wp-content and then rename the ‘plugins’ folder to anything else.
4. Go back to the site and see if the error persists. If not, then the cause for the error was any plugin. Move back to the FTP account and rename the folder to “plugins” again.
5. Access the folders and one by one replace the name of all folders and see the website each time to know which folder is causing the “Error Establishing a Database Connection.”
6. Now either delete the error-making plugin or check for its proper documentation online.
If this error persists, try following the same steps with the ‘themes’ folder.
If the “Error Establishing a Database Connection” is still there, follow the other mentioned steps to solve it.
Fix 4: Updating WordPress Site URL
Try to update your WordPress site URL using phpMyAdmin. Access it from your hosting account dashboard and then select the WordPress database. Next, click on the SQL menu present at the top and enter the following query:
UPDATE wp_options SET option_value=’YOUR_SITE_URL’ WHERE option_name=’siteurl’
Remember that you also have to provide your site URL and change the wp_options to the table names as you change the WordPress table prefix.
Fix 5: Restoring the latest backup:
Finally, if the “Error Establishing a Database Connection” still persists after all these steps, then restore the backup, if required. In some ways, this might be the fastest way of resolving the error, but then you must risk losing the data between now and when the last backup was taken. Remember that if restoring the backup, you must do it with the database and your files.
Conclusion –
There are several ways to help you resolve the “Error Establishing a Database Connection.” Follow the required steps to resolve the error as soon as it occurs or as soon as you identify it. It is essential for saving your website from facing downtime and putting it up as soon as possible for your users.