WordPress Error Establishing a Database Connection is like a curse for those who don't know how to fix this issue. But don't worry, we will discuss in detail to work around this problem.
There are three main reasons behind this error:
1. You database login credentials are wrong, or you have accidentally deleted the wp-config.php file.
2. The database server is unresponsive due to heavy traffic or brute force attack.
3. The database has been corrupted.
Solution # 1: Repair the Database
First, find out that you are getting the same error on both the front and back-end of the site?? If the errors are different on both sides, then repair your database. If they are same, then check our second solution.
Open wp-config.php file and add the following code in the end like:
define('WP_ALLOW_REPAIR', true);
And visit the URL "www.youwebsitename.com/wp-admin/maint/repair.php
Solution # 2: Check For the Login Credentials
Check your wp-config.php file to see whether the database name, username, and password is correct or not. If any of these values are changed, you will get WordPress error establishing a database connection.
Also, check the value of "DB_HOST" that have a default value "localhost." We need to see the DB_HOST value because some hosts may use a different value.
Best way is to use the code like:
define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', $_ENV{DATABASE_SERVER});
Here $_ENV{DATABASE_SERVER} automatically detects the database host.
Solution # 3: Contact Your Web Host
You will have to contact your web host because this error could be caused by heavy traffic coming to your website.
I hope you will be able to fix WordPress error establishing a database connection. If you know, more ways leave those in your comment below. Also, subscribe our channel.
Ещё видео!