Knowledgebase

Fixing "Error Establishing a Database Connection" Print

  • wordpress, database, troubleshooting, errors, php, password, cpanel, https, phpmyadmin, filemanager
  • 0

WordPress cannot reach or authenticate to its database. There are four realistic causes.

1. Wrong credentials in wp-config.php

Open public_html/wp-config.php in File Manager and compare DB_NAME, DB_USER, DB_PASSWORD and DB_HOST against cPanel → MySQL Databases. Remember both the database and user names are prefixed with your cPanel username. DB_HOST should be localhost.

If you are unsure of the password, use MySQL Databases → Current Users → Change Password to set a new one and paste it into wp-config.php.

2. The user is not attached to the database

In MySQL Databases, scroll to Add User To Database, select the pair, and grant ALL PRIVILEGES.

3. A corrupted table

Add this to wp-config.php:

define('WP_ALLOW_REPAIR', true);

Then visit https://yourdomain.com/wp-admin/maint/repair.php and run the repair. Remove the line afterwards — leaving it in place exposes the repair page publicly.

4. Server-side issue

If the credentials are definitely correct and phpMyAdmin will not open the database either, open a support ticket — this may be a MySQL service issue on the server and we will check it immediately.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot