WordPress Error Establishing a Database Connection

WordPress | Updated 2026

"Error establishing a database connection" means WordPress cannot connect to its MySQL/MariaDB database. This is usually caused by incorrect credentials in wp-config.php, a down database server, or a corrupted database.

Most Common Cause

Wrong database credentials in wp-config.php

Open wp-config.php in cPanel File Manager and verify DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST (should be localhost). Then check cPanel > MySQL Databases to confirm the database and user exist and the user is assigned to the database.

01. Check wp-config.php Credentials

Open wp-config.php in your WordPress root directory and find these lines:

define('DB_NAME', 'username_dbname');
define('DB_USER', 'username_dbuser');
define('DB_PASSWORD', 'yourpassword');
define('DB_HOST', 'localhost');

Remember that on cPanel, database names and usernames are prefixed with your cPanel username (e.g., cpuser_wordpress). See Cannot Connect to MySQL for detailed troubleshooting.

02. Verify Database User Permissions

  1. cPanel > MySQL Databases
  2. Scroll to "Current Databases" - Verify your database is listed
  3. Check "Privileged Users" column - Your DB user must be listed
  4. If not assigned, add the user under "Add User To Database" with All Privileges

See How to Add a User to a Database.

03. Repair the Database

If credentials are correct but the database is corrupted, add this to wp-config.php temporarily:

define('WP_ALLOW_REPAIR', true);

Then visit yourdomain.com/wp-admin/maint/repair.php and click "Repair Database." Remove the line from wp-config.php when done.

04. Database Server Down

If everything checks out but you still see the error, the MySQL/MariaDB service may be temporarily down. Test with our MySQL Connection Test. If the server is down, open a ticket immediately.

Database Issues?

Open a Support Ticket

Quick Recap

  1. Check wp-config.php credentials - DB_NAME, DB_USER, DB_PASSWORD, DB_HOST
  2. Verify user is assigned to the database in cPanel > MySQL Databases
  3. DB_HOST should be localhost on shared hosting
  4. Use WP_ALLOW_REPAIR for database corruption
  5. Contact support if the database server is down

WordPress database troubleshooting · Last updated March 2026 · Browse all WordPress articles

  • 174 Users Found This Useful

Was this answer helpful?

Related Articles

How to Disable WordPress Comments Pingbacks and Trackbacks

WordPress | Updated March 2026 WordPress enables comments, pingbacks, and trackbacks by...

JetPack server was unable to connect with your site

Updated 2026 Quick Answer JetPack's connection issues are usually caused by our server...

WordPress Error: The Uploaded File Could Not Be Moved

WordPress | Updated March 2026 The "uploaded file could not be moved to" error in WordPress...

504 Error - Are You Sure You Want to Do This?

WordPress | Updated March 2026 The "Are you sure you want to do this?" message in WordPress...



Save 30% on web hosting - Use coupon code Hosting30