Knowledge Base
Fix “Error Establishing Database Connection” in WordPress
When your WordPress site shows an “Error establishing a database connection” message. This article explains how to resolve database connection errors in WordPress.
The database connection error would occur:
-
if the database server itself malfunctioned or
-
if the database connection string specified by the user is incorrect.
For WordPress. database string is specified in the wp-config.php file located under the website directory.
The connection string has the following details:
-
DB_NAME which is the name of the database
-
DB_USER which is the username of the database user
-
DB_PASSWORD which is the password of the DB_USER
-
DB_HOST which is mostly localhost since the database is on the same server

To Fix this
Fix 1 - Troubleshoot by reimposing database user privileges
- Go to MySQL Databases option in the cPanel
- Check if the DB_USER in the wp-config.php file is present here and see if the user is assigned to the database.
- If yes, click on the user and uncheck ALL PRIVILEGES and click on Make Changes
- Next, Check ALL PRIVILEGES again and click on Make Changes

Check if this solves the issue and if not proceed with below.
Fix 2 - Ensure that the database user exists in cPanel.
-
Modify the database user's password to the password mentioned in the wp-config.php file.
-
Go to cPanel>MySQL databases> Users> database user>Change Password.
If this still does not fix the issue, lets try Fix 3.
Fix 3 - Create a new test database user with a password in MySql databases in cPanel.
-
Assign that user to the database with ALL PRIVILEGES
-
Edit the DB_USER and DB_PASSWORD in the wp-config.php file to your test user. Do make note of the old DB_USER and DB_PASSWORD to revert later.
In case of any queries, please feel free to contact our support team which is available 24x7.