• Wednesday, February 25, 2026

Knowledge Base

How to Fix WordPress Database Connection Error

Resolving Database Issues

"Error establishing a database connection" means WordPress can't connect to MySQL.

Common Causes

  • Wrong database credentials in wp-config.php
  • Corrupted database
  • Database server down
  • Database user permissions

Step 1: Verify Database Credentials

Check wp-config.php for:

define('DB_NAME', 'database_name');
define('DB_USER', 'database_user');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');

Step 2: Test Database Connection

  1. Log into DirectAdmin
  2. Go to MySQL Management
  3. Try accessing phpMyAdmin
  4. If it works, credentials are the issue

Step 3: Check Database User

  1. Go to MySQL Management
  2. Verify the database user exists
  3. Check user permissions
  4. Reset password if needed

Step 4: Repair Database

Add to wp-config.php:

define('WP_ALLOW_REPAIR', true);

Then visit: yourdomain.com/wp-admin/maint/repair.php

Remove the line after repair!

Step 5: Check Database Server

If none of the above works, the database server may be down. Contact support.

Prevention

  • Don't edit wp-config.php unless necessary
  • Regular backups
  • Monitor database size