Database Connection Error in WordPress

The 'Error Establishing a Database Connection' message in WordPress is one of the most alarming errors — but it is usually straightforward to fix.

What Causes This Error?

  • Wrong database credentials in wp-config.php
  • The database user does not have access to the database
  • The MySQL service on the server is temporarily down
  • The database was deleted or renamed

Fix 1: Check wp-config.php Credentials

  1. In cPanel File Manager, navigate to public_html and find wp-config.php.
  2. Right-click and click Edit.
  3. Find these four lines and verify they are correct:
  • define('DB_NAME', 'your_database_name');
  • define('DB_USER', 'your_database_username');
  • define('DB_PASSWORD', 'your_database_password');
  • define('DB_HOST', 'localhost');
  1. To confirm your database name and username: in cPanel, click MySQL Databases and look at the existing databases and users.

Note: Remember that cPanel prefixes database names and usernames with your cPanel account username (e.g., myaccount_wpdb, not just wpdb).

Fix 2: Verify Database User Privileges

  1. In cPanel, click MySQL Databases.
  2. Scroll down to Current Databases and check that your database exists.
  3. Scroll to the Add User To Database section.
  4. Make sure your database user is assigned to the database with ALL PRIVILEGES.

Fix 3: Test Database Connection via phpMyAdmin

  1. In cPanel, click phpMyAdmin.
  2. In phpMyAdmin, check if your database appears in the left panel.
  3. If phpMyAdmin itself is having trouble connecting, the MySQL server may be temporarily down. Contact Hordanso support immediately.

Fix 4: Repair the Database

If the credentials are correct but the error persists, the database may be corrupted. Add this line to wp-config.php (after the database credentials):

define('WP_ALLOW_REPAIR', true);

Then visit: yourdomain.com/wp-admin/maint/repair.php and click Repair Database. Remove the line afterwards.

 

  • database error, MySQL error, error establishing connection, WordPress database, wp-config
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

My Website is Down — First Steps to Diagnose

If your website is not loading, here is a quick checklist to diagnose the problem before...

500 Internal Server Error — Causes and Fixes

A 500 Internal Server Error is a generic message that means your web server encountered a problem...

Accepted Payment Methods at Hordanso

Here is a complete list of all the payment methods Hordanso accepts, for both Nigerian and...

ERR_TOO_MANY_REDIRECTS — How to Fix

The ERR_TOO_MANY_REDIRECTS error means your website is redirecting back and forth between URLs...

Email Not Receiving — Troubleshooting Guide

If emails sent to your domain are bouncing or not arriving, here is a structured guide to...

Powered by WHMCompleteSolution