Fixing “Error Establishing a Database Connection” (Firstserv Guide)
This error means your WordPress site is unable to connect to its database. It is commonly caused by:
- Incorrect database credentials
- Database user or permissions issues
- Corrupted database
- Temporary server or database problems
Follow the steps below to identify and resolve the issue.
1. Check Database Details in wp-config.php
Start by verifying your database connection settings.
Steps:
- Log in to cPanel
- Open File Manager
- Navigate to your WordPress directory (usually
/public_html/) - Open the
wp-config.phpfile
Look for the following lines:
Check the following values:
- DB_NAME – Your database name
- DB_USER – The database username
- DB_PASSWORD – The password for that user
- DB_HOST – Usually
localhost
2. Verify Database and User in cPanel
Next, confirm that these details match your actual MySQL configuration.
Steps:
- In cPanel, go to MySQL Databases
- Under Current Databases, check:
- The database name exists
- Confirm:
- The correct user is assigned to that database
✅ If anything doesn’t match:
- Update the
wp-config.phpfile with the correct details
3. Reset the Database User Password
If credentials appear correct but the error persists, the password may be incorrect.
Steps:
- In cPanel → MySQL Databases
- Locate your database user under Current Users
- Click Change Password
- Set a new strong password
Then update your wp-config.php:
Save the file and retry your website.
4. Check User Permissions
The database user must have the correct permissions to access and modify the database.
Steps:
- In cPanel → MySQL Databases
- Scroll to Add User to Database
- Select the correct:
- User
- Database
- Click Add
- On the next screen, select All Privileges
- Click Make Changes
✅ This ensures the user has full access required by WordPress.
5. Additional Checks (If Issue Persists)
If the problem continues, consider:
- ✅ Database corruption – attempt a repair via phpMyAdmin
- ✅ Server issues – temporary database downtime
- ✅ Incorrect DB_HOST – some advanced setups use a different hostname
Summary
To resolve database connection errors:
- Verify credentials in
wp-config.php - Confirm database and user settings in cPanel
- Reset the database password if needed
- Ensure the user has full database permissions
If you’re unable to resolve the issue after these steps, the Firstserv support team can help investigate and restore your connection quickly.
