Get a free website with any plan

See how
WORDPRESS

Fixing WordPress database connection errors

If WordPress shows "Error establishing a database connection" — no homepage, no admin — the WordPress code can't reach its database. Usually a configuration issue, sometimes a server issue.

Check wp-config.php

Open wp-config.php via FTP or the file manager. Look for:

define('DB_NAME', 'youraccount_wordpress');
define('DB_USER', 'youraccount_wpuser');
define('DB_PASSWORD', 'somepassword');
define('DB_HOST', 'localhost');

Check each:

  • DB_NAME — must exist as a database in cPanel → MySQL Databases. Names usually have a youraccount_ prefix.
  • DB_USER — the user WordPress connects as. Same prefix convention.
  • DB_PASSWORD — what you set when creating the user. If you've forgotten it, change the password in cPanel and update wp-config.php.
  • DB_HOSTlocalhost for our hosting. Some hosts use a specific server name; ours doesn't.

If any value is wrong, fix it and reload the site.

Common causes

Password recently changed

If you changed the database user's password in cPanel but didn't update wp-config.php, this is the culprit. Update wp-config.php with the new password.

Database doesn't exist

If the database wp-config.php references doesn't exist (deleted, renamed, was never created):

  1. Open phpMyAdmin from your hosting.
  2. Look for the database.
  3. If missing, create it (via cPanel → MySQL Databases).
  4. If it exists under a different name, update wp-config.php to match.

User doesn't have access to the database

The database exists, the user exists, but the user doesn't have privileges:

  1. cPanel → MySQL Databases → scroll to "Add User to Database."
  2. Pick the user and the database.
  3. Grant All Privileges.
  4. Save.

WordPress can now connect.

Database server is down

Rare. If our database server is having issues, you'd see this error site-wide and we'd have a status page entry. Check status.flashcloud.com.

If the status page shows we're up but you're getting connection errors, open a ticket — it could be a database-specific issue we need to fix.

Database corruption

Even rarer. WordPress's "Database Repair" mode can fix:

  1. Add to wp-config.php:
    define('WP_ALLOW_REPAIR', true);
    
  2. Visit https://yourdomain.com/wp-admin/maint/repair.php.
  3. Click Repair Database or Repair and Optimize Database.
  4. After it finishes, remove the line from wp-config.php (don't leave it on — anyone could trigger repair otherwise).

wp-config.php is corrupted

If you recently edited wp-config.php and it has a syntax error, WordPress can't parse it. Symptoms vary — sometimes white screen, sometimes the database error.

To check:

  • Verify there are no missing semicolons, unclosed quotes, or stray characters.
  • Compare against wp-config-sample.php (in the WordPress folder) for reference.
  • If unsure, replace with a clean copy of wp-config.php from a backup.

Diagnosing further

If the basics check out and the error persists:

Test the database connection manually

Create a file called test-db.php in your WordPress folder:


Replace credentials with your actual ones. Visit https://yourdomain.com/test-db.php. If it says "Connected successfully," WordPress's wp-config.php has wrong credentials. If it shows an error, the credentials themselves are wrong.

Delete this file when done — leaving it accessible exposes your database credentials.

Check error logs

cPanel → Error Log shows recent server errors. Often there's a specific MySQL error message that explains the issue.

Or check wp-content/debug.log if you've turned on WP_DEBUG.

After fixing

Once the connection is restored:

  • Verify all pages load — sometimes a partial fix leaves admin working but frontend broken.
  • Check error logs for repeated issues.
  • Make a backup — now is a good time, given the recent scare.

Power-user note

For sites with extreme database load (very large or busy), consider:

  • Database optimization plugins (WP-Optimize) to clean up bloat.
  • Object cache (Redis on Flashcloud is automatic) reduces database queries.
  • Split databases — for huge sites, having WordPress in one database and other apps in others can help isolate load.

For most sites, the standard MariaDB + Redis setup on our hosting handles everything fine.

CAN'T FIND IT?

Real humans answer fast.

Hosting with us? Open a ticket and a real person replies - no scripts, no upsells. Still choosing a host? The same team is included with every plan, from day one.