How to Fix Error Establishing a Database Connection in WordPress
Quick Summary
The WordPress error “Error establishing a database connection” means WordPress cannot connect to its database.
Common Causes
- Wrong database name
- Wrong database username
- Wrong database password
- Wrong database host
- Database user missing permissions
- Database server issue
- Corrupted database
- wp-config.php misconfigured
Step 1: Check wp-config.php
- Log in to cPanel.
- Open File Manager.
- Open your WordPress folder.
- Find wp-config.php.
- Check these values:
DB_NAME
DB_USER
DB_PASSWORD
DB_HOST
Common DB_HOST value:
localhost
Step 2: Check MySQL Databases
- Log in to cPanel.
- Open MySQL Databases.
- Confirm the database exists.
- Confirm the database user exists.
- Confirm the user is assigned to the database.
Step 3: Assign User to Database
- Go to MySQL Databases.
- Find Add User to Database.
- Select the database user.
- Select the database.
- Click Add.
- Select All Privileges.
- Save changes.
Step 4: Reset Database Password
If unsure, reset the database user password and update wp-config.php with the new password.
Step 5: Repair Database
If WordPress database is corrupted, you may need database repair.
Create a backup before making database changes.
Common Problems
Problem: Website worked before and suddenly broke.
Solution: Check if database password or user permissions changed.
Problem: Error appeared after migration.
Solution: Check wp-config.php database details.
Problem: Error appeared after restoring backup.
Solution: Confirm the database was imported correctly.
Need Help?
Open a support ticket:
