How to Fix “Error Establishing a Database Connection” in WordPress
This guide shows you how to fix the “Error Establishing a Database Connection” issue in WordPress. This error means your website cannot connect to its database, usually due to incorrect settings, missing permissions, or database issues.
What Causes This Error?
This error occurs when WordPress cannot connect to your MySQL database. This is typically caused by incorrect credentials, missing database permissions, corrupted tables, or server issues.
Incorrect Database Credentials
Database name, username, or password is incorrect in wp-config.php.
Database User Not Assigned
The user does not have permission to access the database.
Corrupted Database
Tables may be damaged and need repair.
Server Issues
The database server may be temporarily unavailable.
Step-by-Step Fix
Fix Using cPanel
Step 1: Check wp-config.php
Go to File Manager → public_html and open wp-config.php.
Verify:
DB_NAME
DB_USER
DB_PASSWORD
DB_HOST (usually localhost)
Step 3: Assign User
Ensure the database user has full privileges.
Fix Using DirectAdmin
Step 1: Check wp-config.php
Go to File Manager → domains → yourdomain.com → public_html.
Open wp-config.php and verify database credentials.
Step 2: Check Database
Go to MySQL Management and confirm your database exists.
View DirectAdmin Database GuideStep 3: Assign User
Ensure the database user is assigned with full privileges.
Quick Fix (Advanced)
Enable WordPress Repair Mode
Add this line to your wp-config.php file:
define('WP_ALLOW_REPAIR', true);
Then visit:
yourdomain.com/wp-admin/maint/repair.php
Common Issues & Fixes
Access Denied
Reassign database user with full privileges.
Database Missing
Restore from a backup if available.
Still Not Working
Double-check credentials and server status.