Skip to content

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.

Medium Difficulty
10–20 min Time
WordPress Required

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

Check Config
Verify DB
Assign User
Repair

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 2: Check Database

Go to MySQL Databases and confirm it exists.

View cPanel Database Guide

Step 3: Assign User

Ensure the database user has full privileges.

Step 4: Repair Database

Use phpMyAdmin to repair tables.

Open phpMyAdmin Guide

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 Guide

Step 3: Assign User

Ensure the database user is assigned with full privileges.

Step 4: Repair Database

Open phpMyAdmin and repair tables if needed.

Open phpMyAdmin Guide

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.

Related Guides

Create Database

Set up your database correctly.

cPanel Guide
DirectAdmin Guide

phpMyAdmin

Manage and repair your database.

cPanel Guide
DirectAdmin Guide

Restore Backup

Restore your site if needed.

cPanel Guide
DirectAdmin Guide
← Back to Troubleshooting