If you can’t visit your website & see Error Establishing a Database Connection so this article will help you and after reading you will be able to fix it easily without hiring someone.
Please make your website backup before applying any of this method. If you are not able to login to your web so simply make a backup from Cpanel. Learn How to Make WordPress Backup from Cpanel (Tutorial).
Why this error appears?
There are many reasons that you get this error, but in short, we will say, You get this because WordPress can’t connect to a database.
- The reason can be because your database is unresponsive.
- Your WordPress Database has been corrupted or corrupting.
- Some server error
- Changing database name or deleting it yourself
Please Note: If the Error Establishing a Database Connection is just appeared on your login page mean when you try to login to your WordPress then try the following option. But if the error appears on the complete website mean on every page then try to follow other methods.
Add the following line just before ‘That’s all, stop editing! Happy blogging’ line in wp-config.php.
Once you add the above coding then simply visit: http://www.yoursite.com/wp-admin/maint/repair.php
Keep in mind, the user does not need to be logged in to access this functional when this define is set. Because the main intent is to repair a corrupted database. Users can not login in most case when a database is corrupted. So when you’re done repairing and optimizing a database, so remove it from your wp-config.php.
1.Checking the WP-Config file
WP-Config.Php is the most powerful and important file in your WordPress.
It has many details included WP-Database username & password, When you change a database username or password so you must change in wp-config.php file too, otherwise you will get the Error Establishing a Database Connection.
Note: Most of hosting server has DB_Host is “localhost” but you have to ask it from the hosting provider or you can Google it.
Change database name, username, password if you’ve changed it if not then check your database details.
2.Check Web Host (MySQL Server)
Probably you noticed, most of the time the Error Establishing a Database Connection appears because your site got too much traffic and your bandwidth got limited.
You should contact your hosting provider and ask them that check your site MySQL server. If the problem is because of that so you have to wait for it so your bandwidth can back to the normal position or you have to upgrade your hosting plan package.
In most cases, it happens with shared hosting user.
Also Read: How to Fix the Syntax Error in WordPress