Hosting & Migration 5 min read

Fixing ‘Error establishing a database connection’ in WordPress

How to fix 'Error establishing a database connection' in WordPress: checking wp-config.php credentials, database server status, corrupted databases, limits and hacks.

Usman Muhammad UsmanUpdated October 13, 2026
Fixing ‘Error establishing a database connection’ in WordPress

‘Error establishing a database connection’ means WordPress cannot talk to its database, so it cannot load any content. The whole site, including the admin area, usually shows the same message. The cause is often simple, such as wrong login details or a database server under strain. Here is how I diagnose and fix it, step by step.

What the error means

WordPress stores posts, pages, settings and users in a MySQL or MariaDB database. On every page load, it connects using details in wp-config.php. If the connection fails, WordPress shows this error instead of the page.

Possible causes include incorrect database credentials, a database server that is down or overloaded, a corrupted database, hosting limits or, occasionally, a hack that changed files.

Check if the problem is site-wide

Visit the front end and /wp-admin/. If both show the error, the connection is failing completely. If the admin area shows a different message about repairing the database, the database may be corrupted.

Check whether other sites on the same hosting account are also affected. If they are, the database server itself is probably having problems.

Fixing the database error
  1. 1Ask your hostServer status
  2. 2Check wp-config.phpName, user, password, host
  3. 3Reset credentialsUpdate to match
  4. 4Repair tablesWP_ALLOW_REPAIR
  5. 5Restore backupIf damaged

Check with your host

Contact your host or check their status page. Database servers sometimes go down for maintenance or due to problems, and the host may already be fixing it. On shared hosting, an overloaded database server can cause intermittent errors.

This is often the quickest way to find the cause, so ask early rather than spending time on other checks.

Verify wp-config.php details

Open wp-config.php using the host’s file manager or SFTP. Check DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Compare them with the database details in your hosting panel, such as MySQL Databases in cPanel. A single typo breaks the connection.

DB_HOST is usually localhost, but some hosts use a different hostname or port. Your host’s documentation lists the correct value.

Test the database credentials

In your hosting panel, log in to phpMyAdmin with the database user if possible, or check that the user is assigned to the database with all privileges. If the password may have changed, reset the database user’s password in the panel and update wp-config.php to match.

After migrations, it is common for the database name or user to differ on the new host. See moving WordPress between hosts.

Repair a corrupted database

If tables are corrupted, WordPress can attempt a repair. Add a line defining WP_ALLOW_REPAIR as true in wp-config.php, then visit yourdomain.com/wp-admin/maint/repair.php and choose Repair Database. Remove the line afterwards, as the repair page does not require a login.

phpMyAdmin also has a repair option for individual tables. Take a backup before repairing.

Check the site URL in the database

If credentials are correct and the database works, check the siteurl and home values in the wp_options table, or the table with your custom prefix. Incorrect values, often after migrations, can cause different errors, but sometimes combine with connection issues.

Fix URLs carefully, ideally with WP-CLI or a search and replace tool that handles serialised data.

Hosting limits and traffic spikes

On shared hosting, a sudden traffic spike or a heavy plugin can exceed database connection limits, causing the error intermittently. Server logs or your host can confirm this.

Page caching reduces database load significantly. Object caching with Redis helps further. If the site regularly hits limits, it may need better hosting. See choosing WordPress hosting.

Check for a hack

Occasionally, attackers modify wp-config.php or database credentials. If the file contains unfamiliar code, or credentials changed without explanation, treat it as a security incident. Scan the site and check for other signs of compromise.

See what to do when your WordPress site is hacked.

Restore from backup

If the database is badly damaged or lost, restore the most recent database backup. Your host may have one, or your backup plugin’s off-site copies can be imported via phpMyAdmin. See how to restore a WordPress backup.

After restoring, check for content added since the backup and recover it if possible.

Prevent it happening again

Use reliable hosting, enable page and object caching, keep regular backups and monitor uptime so you are alerted immediately. Avoid editing wp-config.php without a backup.

Uptime monitoring tells you about outages before customers do. See website uptime monitoring.

A white screen or ‘critical error’ message is usually a PHP problem rather than a database connection issue; see fixing the WordPress critical error. Memory errors are covered in increasing the PHP memory limit.

Knowing which error you are seeing helps you go straight to the right fix.

Getting help

If your site is down with a database error and you need it fixed quickly, contact me. Emergency fixes and ongoing monitoring are part of my website protection service.

For a monthly prevention routine, see my maintenance checklist.

Key takeaways

  • The error means WordPress cannot connect to its database.
  • Check with your host first, then verify wp-config.php credentials.
  • Use the built-in repair tool for corrupted tables and remove it afterwards.
  • Caching and better hosting prevent errors caused by traffic spikes.

Frequently asked questions

Is my content lost?

Usually not. The content is in the database; WordPress just cannot connect to it.

Why did this happen after moving hosts?

Database names, users or hosts often differ on the new server. Update wp-config.php.

Is the repair page safe?

It works without login, so remove the WP_ALLOW_REPAIR line as soon as you finish.

Why does the error come and go?

Often the database server is overloaded or hitting connection limits.

Can a plugin cause this error?

Indirectly, by overloading the database, but most causes are credentials or server problems.

What is DB_HOST?

The address of the database server, often localhost.

Can I fix this without a developer?

Often yes. Checking with your host and verifying the details in wp-config.php solves most cases. Get help if the database is corrupted or you suspect a hack.

Will caching hide the error?

Cached pages may still load for some visitors while the database is down, but the admin area, forms and uncached pages will show the error.

Free website audit

Get a free audit of your website

Tell me your URL and I'll send a short, prioritized list of the speed, SEO and security fixes that will make the biggest difference.

  • No obligation, no sales call
  • 5.0 rating on Google and Upwork
  • Reply within one business day
Written by Muhammad UsmanWeb Development Team Lead with 5+ years building WordPress, WooCommerce, Shopify and Wix websites. Experience · Certificates About me

More on Hosting & Migration

All Hosting & Migration articles

Have a project in mind?

Tell me what you're building and I'll reply with next steps and an estimate.