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

WordPress Error : Sorry, this file type is not permitted for security reasons

WordPress | Updated March 2026 The "Sorry, this file type is not permitted for security...

WordPress Site Search

WordPress | Updated 2026 WordPress includes a built-in site search that lets visitors find...

How to Install WordPress

WordPress | Updated March 2026 Installing WordPress on your Ultra Web Hosting account takes...

CloudFlare for WordPress

Cloudflare + Web Hosting Guide | Updated 2026 Cloudflare is a content delivery network (CDN)...

How to Fix a Hacked WordPress Site

WordPress Security | Updated 2026 If your WordPress site has been hacked, defaced, or is...



Save 30% on web hosting - Use coupon code Hosting30