How To Fix Error Establishing a Database Connection in cPanel
🛠Fix “Error Establishing a Database Connection” in cPanel
The “Error Establishing a Database Connection” message usually happens because of wrong database credentials or missing privileges.
To fix it, we need to make sure:
-
âś… Database name matches the actual database.
-
âś… Database username matches the assigned user.
-
âś… Database password is correct.
-
âś… User has all privileges for the database.
🔹 Step 1: Locate Database Details in wp-config.php
-
Login to cPanel.
-
Open File Manager.
-
Go to the root folder of your WordPress installation.
-
Open the file wp-config.php.
Inside, look for these lines:
Note down the DB_NAME, DB_USER, and DB_PASSWORD values.
🔹 Step 2: Verify Database in MySQL Databases
-
In cPanel, go to MySQL Databases.
-
Confirm the Database Name matches
DB_NAMEfromwp-config.php. -
Scroll down to check the Database Users section.
-
Ensure the Username matches
DB_USERfromwp-config.php.
🔹 Step 3: Reset Database User Password
-
In MySQL Databases, reset the user password.
-
Update
DB_PASSWORDin wp-config.php with the new password.
🔹 Step 4: Assign User Privileges
-
In MySQL Databases, scroll to Add User to Database.
-
Select your user and database.
-
Check All Privileges.
-
Click Make Changes.
You should now see a confirmation message:
✅ “The MySQL User has been successfully added to the Database with all privileges.”
🔹 Step 5: Test Your Website
Reload your WordPress site. The Error Establishing a Database Connection issue should now be fixed.
⚡ Pro Tip: If the error persists, check your DB_HOST value in wp-config.php. For most cPanel servers it’s localhost, but some hosts use a different hostname (like 127.0.0.1 or mysql.yourdomain.com).
Share
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0
