Skip to main content

Your privacy

We store what the site needs to work, like a notice you closed or your domain shortlist. With your OK we also use Google Analytics to see which pages help people, and the Meta Pixel to measure which of our adverts work. Privacy policy

Serverlys
Recovery

Fix “Error establishing a database connection”

Find out which of the four usual causes it is, in the order that is quickest to check.

All Recovery tutorials6 stepsAbout 15 minutes

Before you start

  • Control panel access, or SSH
  • Access to wp-config.php
  1. Step 1: Check /wp-admin as well as the homepage

    If /wp-admin says one or more database tables are unavailable and the database may need to be repaired, WordPress connected but found damaged tables — skip to the repair step. If it shows the same connection error, the credentials or the database server are the problem.

  2. Step 2: Compare wp-config.php with the panel

    DB_NAME, DB_USER, DB_PASSWORD and DB_HOST must match a real database and user. On cPanel, MySQL Databases lists both and shows whether the user is added to that database. After a migration, a wrong name prefix or a user never added to the database is the usual cause.

    define( 'DB_NAME', 'cpuser_wp' );
    define( 'DB_USER', 'cpuser_wpuser' );
    define( 'DB_PASSWORD', '…' );
    define( 'DB_HOST', 'localhost' );
  3. Step 3: Reset the password if unsure

    cPanel cannot show you a database user's password, only change it. Set a new one in MySQL Databases, then paste the same value into DB_PASSWORD. DB_HOST is localhost on most cPanel servers; a site moved from another host may still carry that host's value.

  4. Step 4: Test the credentials directly

    Over SSH, connect with the same details. Access denied means the user, password or privileges are wrong. Can't connect to the server means the database service itself is not answering — report that exact message to your host, as there is nothing to fix in WordPress.

    mysql -u cpuser_wpuser -p -h localhost cpuser_wp
    # or, using wp-config.php's own values:
    wp db check
  5. Step 5: Repair damaged tables

    Add the line below to wp-config.php, open /wp-admin/maint/repair.php and run Repair Database. Remove the line as soon as it finishes.

    define( 'WP_ALLOW_REPAIR', true );
  6. Step 6: Look for a resource limit

    If the error comes and goes under traffic, the account may be hitting its database connection or memory limits. The error log in the control panel shows when it happens; caching pages reduces how many requests reach the database at all.

The mistake people make

Leaving WP_ALLOW_REPAIR in wp-config.php. The repair page does not require a login, so anyone who finds it can run repairs and optimisations against your database whenever they like.

Stuck on something not covered here?

Support is included on every plan, and it reaches a person. There is also the blog for the why behind these, and the FAQ for questions about buying.

Get help

A plan that still makes sense in year two

Free migration, free SSL and daily backups on every plan, with a 30-day money-back guarantee.

Prefer the phone? (305) 671-1272 · Existing customer? Client login