Skip to content
Websites · Down or broken

'Error establishing a database connection' or a 500 error: what to check

Your WordPress site shows 'Error establishing a database connection' or a 500 error. What each means and what to check, in order.

By Miro, Wave Digital. Updated .

"Error establishing a database connection" means WordPress can't reach the database that holds your content, usually because the login details are wrong or the database server is down. A 500 error means the server hit a problem it couldn't name, most often a broken .htaccess file, a plugin or theme, or PHP running out of memory. Neither means your content is gone.

Diagram: the browser asks the web server, which runs PHP and WordPress, which reads the database. A 500 error comes from the web server and PHP. The database error comes from WordPress failing to reach the database.
Where along the way each error comes from

If you see "There has been a critical error on this website" instead, a plugin or theme has crashed. Follow a plugin update broke my site.

Database connection error

  1. Ask your host if the database server is down or over its quota. It's the quickest check.
  2. Check wp-config.php. In your hosting file manager, compare DB_NAME, DB_USER, DB_PASSWORD and DB_HOST with the database and user in your control panel. A changed password or a recent move often leaves old details here.
  3. Repair the tables if WordPress asks. If you see "One or more database tables are unavailable", add define( 'WP_ALLOW_REPAIR', true ); to wp-config.php above "That's all, stop editing!", then open yourdomain.co.nz/wp-admin/maint/repair.php and click Repair Database. Remove the line straight after, because while it's there anyone can open that page without logging in.
  4. Rule out a hack. If everything checks out and the error keeps coming back, see website hacked.

500 error

  1. Read the error log. In cPanel it's under Metrics, then Errors. The newest lines often name the file or plugin at fault.
  2. Rename .htaccess to .htaccess_old in the site's main folder and reload. If the site comes back, go to Settings, then Permalinks and click Save Changes to make a fresh one.
  3. Switch off plugins by renaming wp-content/plugins to plugins-off. If the site returns, rename it back and turn plugins on one at a time.
  4. Switch theme by renaming your theme's folder in wp-content/themes.
  5. Ask your host to raise the PHP memory limit if the log says memory was exhausted.

An old PHP version can also cause a 500 after a plugin update. See PHP version out of date.

When to get help

If nothing works, restoring a backup from before the problem is often the fastest way back. Hand it over if you can't get into your hosting control panel, the repair tool doesn't fix the tables, or you have no recent backup. Editing wp-config.php or the database by hand without a backup can turn a short outage into lost content.

If your site is down now, talk to us.

Is your site slow on phones, out of date or marked "Not secure"?

Put in your web address and find out free in about 30 seconds.

Rather not deal with this yourself?

We find which part has failed, fix it and get the site back, restoring from a backup if we need to. With Website Cover, we host it, watch it day and night and keep daily backups.

Website Cover is $95 a month + GST. We move your website over, fix this and everything else on our list, and keep it fixed. No contract.