How To Fix Error Establishing a Database Connection in cPanel

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

  1. Login to cPanel.

  2. Open File Manager.

  3. Go to the root folder of your WordPress installation.

  4. Open the file wp-config.php.

Inside, look for these lines:

define('DB_NAME', 'your_db_name'); define('DB_USER', 'your_db_user'); define('DB_PASSWORD', 'your_db_password'); define('DB_HOST', 'localhost');

Note down the DB_NAME, DB_USER, and DB_PASSWORD values.


🔹 Step 2: Verify Database in MySQL Databases

  1. In cPanel, go to MySQL Databases.

  2. Confirm the Database Name matches DB_NAME from wp-config.php.

  3. Scroll down to check the Database Users section.

  4. Ensure the Username matches DB_USER from wp-config.php.


🔹 Step 3: Reset Database User Password

  1. In MySQL Databases, reset the user password.

  2. Update DB_PASSWORD in wp-config.php with the new password.


🔹 Step 4: Assign User Privileges

  1. In MySQL Databases, scroll to Add User to Database.

  2. Select your user and database.

  3. Check All Privileges.

  4. 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 Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0