Skip to content

Fix 'Error Establishing a Database Connection' in WordPress

Fix WordPress database connection error

This error means WordPress cannot connect to its database. The cause is usually one of these:

  • Wrong database name, username, or password in wp-config.php
  • Wrong database host value
  • Database server down or overloaded
  • Corrupted database tables

Follow the steps in order. Don't change multiple things at once.


Step 1: Confirm the database exists and is reachable

In cPanel

  1. Open phpMyAdmin
  2. Select the database from the left sidebar
  3. If it opens and tables are visible, the database server is up

If phpMyAdmin also fails, it points to a server or credential issue.


Step 2: Verify wp-config.php database credentials

Edit wp-config.php in your WordPress root and confirm:

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

Common mistakes: - DB_NAME or DB_USER missing the hosting prefix (common on shared hosting) - DB_PASSWORD changed but WordPress wasn't updated - DB_HOST set incorrectly


Step 3: Reset the database user password (fastest correction)

In cPanel

  1. Open MySQL Databases
  2. Find the database user
  3. Change the password
  4. Update DB_PASSWORD in wp-config.php

Reload the site.


Step 4: Repair corrupted database tables

Enable repair mode temporarily:

define('WP_ALLOW_REPAIR', true);

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

Run Repair Database.

Remove the line from wp-config.php when finished.

Warning

Do not leave repair mode enabled. The repair page can be accessed without logging in.


Step 5: Restore DB user privileges (if needed)

If the DB user exists but has no access:

In MySQL Databases: 1. Add the correct user to the database 2. Grant ALL PRIVILEGES

Reload the site.


Step 6: Resource events (intermittent failures)

If the error appears only sometimes, it can be a load spike: - heavy plugin tasks - slow queries - traffic bursts

Enable caching and reduce heavy tasks.


When to contact GOZEN HOST Support

Open a ticket if: - phpMyAdmin cannot load any database - credentials are correct and the error persists - the issue happens intermittently (likely load-related)

Include: - domain - time of error - whether phpMyAdmin works - DB_NAME/DB_USER/DB_HOST values (no passwords)


Summary

Fixes in order: phpMyAdmin check → wp-config credentials → reset DB password → repair tables → restore privileges → evaluate resources.