How to Fix "Error Establishing a Database Connection" in WordPress

"Error establishing a database connection" means WordPress can't talk to its MySQL database, so it can't load any page. The good news is that the database itself is almost always fine -- it's usually a mismatch between the login details in wp-config.php and the database user in cPanel. This guide walks you through finding and fixing the WordPress database connection error step by step.

Common causes

  • The database password in wp-config.php doesn't match the database user's password (often after someone changed it in cPanel).
  • The database name or username is wrong -- for example after moving the site from another host.
  • The database user was never added to the database, or lost its privileges.
  • A damaged database table.
  • Your account hit its resource limits for a moment during a traffic spike.

Step 1: Look at the database details in wp-config.php

  1. Log in to cPanel and go to Files > File Manager.
  2. Open public_html (or the folder where WordPress is installed), select wp-config.php and click Edit.
  3. Find these lines and note the values:
    define( 'DB_NAME', 'cpuser_wp123' );
    define( 'DB_USER', 'cpuser_wpuser' );
    define( 'DB_PASSWORD', 'the-password' );
    define( 'DB_HOST', 'localhost' );

On Instant Access Internet Services servers, database names and usernames always start with your cPanel username and an underscore, and DB_HOST should be localhost.

Step 2: Check the database and user exist in cPanel

  1. In cPanel, go to Databases > Manage My Databases.
  2. Under Current Databases, check that a database with exactly the DB_NAME value exists.
  3. In the same row, look at the Privileged Users column. The DB_USER value should be listed there.

If the names don't match anything, the site may be pointing at an old database. Correct DB_NAME and DB_USER in wp-config.php to match the database and user shown in cPanel.

Step 3: Reset the database user's password

This is the fix in most cases. You set a new password in cPanel, then put the same password in wp-config.php.

  1. In Databases > Manage My Databases, scroll to Current Users.
  2. Next to the user from DB_USER, click Change Password.
  3. Enter a new strong password (or use the Password Generator) and copy it. Click Change Password.
  4. Back in File Manager, edit wp-config.php and paste the new password between the quotes on the DB_PASSWORD line. Be careful not to remove the quote marks or the semicolon.
  5. Click Save Changes and reload your website.

Step 4: Make sure the user has privileges on the database

  1. In Manage My Databases, go to Add User To Database.
  2. Choose the user from DB_USER and the database from DB_NAME, then click Add.
  3. Tick ALL PRIVILEGES and click Make Changes.

Step 5: Repair the database

If the details are all correct but the error continues, or the WordPress admin says one or more tables are unavailable, repair the database:

  1. In Manage My Databases, find Modify Databases.
  2. Choose your database under Repair Database and click Repair Database.

Still getting the error?

  • It comes and goes. If the site works most of the time but shows the error during busy periods, check Metrics > Resource Usage for limit hits. Turning on LiteSpeed Cache usually fixes this.
  • It started after a restore or migration. The database may be empty or missing. Check in Databases > phpMyAdmin that the database has tables. If not, restore the database with JetBackup 5.
  • It started after a hack or plugin change. Restore from a backup taken before the problem, then change your passwords.

Related guides

Still stuck? Open a support ticket and the Instant Access Internet Services team will help.

Ultrafast LiteSpeed hosting from InstantAccess.net: free SSL, free backups, cPanel included, no contracts. Check out our $10/month hosting.
  • error establishing a database connection, wordpress database error, wp-config.php database settings, wordpress database connection fix, cpanel database user password, wordpress site down
  • 0 Bu dökümanı faydalı bulan kullanıcılar:
Bu cevap yeterince yardımcı oldu mu?

İlgili diğer dökümanlar

How to Create a WordPress Staging Site and Push It Live

A staging site is a private copy of your WordPress website where you can test new plugins, theme...

How to Install WordPress with WP Toolkit in cPanel

WP Toolkit lets you install WordPress on your hosting account in a couple of minutes, with no...

How to Log In to WordPress Admin from WP Toolkit

You don't need to remember your WordPress password to get into your site. WP Toolkit in cPanel...

How to Update WordPress, Plugins and Themes (and Turn On Auto-Updates)

Keeping WordPress up to date is the single best thing you can do to keep your site safe. This...

How to Move a WordPress Site from Another Host (WP Toolkit Import)

Moving a WordPress site from another host doesn't have to mean downtime or lost content. This...