Error Establishing a Database Connection
Infrastructure Editor
Disclosure: Some links on this page are affiliate links — if you sign up through one, we may earn a commission at no extra cost to you. It never changes our ratings, rankings or verdicts: we don't sell hosting and take no pay-for-placement.
Who it's for
- WordPress site owners
- Site admins after a migration
- Developers debugging a dynamic site
- Agencies managing client CMS sites
By Marcus Feld, Infrastructure Editor
Error Establishing Database Connection: What “Error Establishing a Database Connection” Means
“Error establishing a database connection” is a specific failure message shown by WordPress and many other database-driven CMS platforms when the web application successfully loads but can’t reach the database that stores your posts, pages, settings, and users. It’s a narrower, more specific variant of the general 500 Internal Server Error. The web server itself is fine, but the connection between the application and its database has broken.
Common Causes, Ranked
Incorrect Database Credentials
Wrong credentials in the configuration file (wp-config.php for WordPress) often follow a migration, a host change, or a manual edit that introduced a typo.
Database Server Down or Unreachable
The database service itself has crashed, restarted, or is temporarily overloaded and refusing new connections.
Corrupted Database Tables
An interrupted update, a bad plugin operation, or an incomplete migration leaves core tables damaged.
Too Many Simultaneous Database Connections
The hosting plan’s connection limit is exceeded during a traffic spike, and new connection attempts are refused.
Wrong Database Host Value
This is especially common after switching hosts, where the database server address isn’t localhost and needs an updated value.
Database Server Resource Limits
The database server can hit its own memory or disk space limits on the specific server instance, independent of your website’s traffic.
Step-by-Step Fix
- Check the database credentials in your configuration file (for WordPress:
DB_NAME,DB_USER,DB_PASSWORD,DB_HOSTinwp-config.php) against the actual values in your hosting control panel’s database section. - Confirm the database user has the correct permissions on the specific database it’s meant to access — a permissions mismatch produces this exact error even with a correct password.
- Check the
DB_HOSTvalue specifically after any host migration — it’s frequentlylocalhostbut can be a different internal address depending on the provider. - Check whether the database server is reachable via your hosting control panel’s database tool (phpMyAdmin or equivalent) — if that also fails to connect, the fault is at the database server itself, not your config.
- Run a database repair using your CMS’s built-in tool (WordPress: add
define('WP_ALLOW_REPAIR', true);towp-config.php, then visit/wp-admin/maint/repair.php) if credentials are confirmed correct but the error persists. - Check active database connections in your hosting dashboard against your plan’s limit, especially if the error appears mainly during traffic spikes.
- Restore from a recent backup if a table is confirmed corrupted beyond what a repair tool can fix, and the timing lines up with a specific bad update or interrupted process.
- Contact hosting support if the database server itself is confirmed down, or if resource limits at the server level (not just your plan) are the bottleneck — that requires action on their side.
How to Prevent Database Connection Errors
- Always update database credentials in the config file immediately after a migration or host change, and test the connection before pointing DNS at the new server.
- Run periodic database optimization to keep tables healthy and reduce the chance of corruption during routine operations.
- Keep automated backups running so a corrupted database is a restore, not a rebuild.
- Monitor database connection usage if your site runs plugins or integrations that open many simultaneous queries.
- Avoid manual database edits outside your CMS’s own tools unless you know exactly what you’re changing.
- Check your plan’s connection limits against your traffic when choosing a reliable host in the first place — undersizing here is a recurring, avoidable cause.
When to Contact Your Host
Contact your host once you’ve confirmed the credentials, host value, and permissions in your configuration file are correct, and the database server itself is unreachable from your control panel’s own database tool. That combination points to a fault on the database server or its resource allocation. It’s outside what you can fix from the application side. See the 500 Internal Server Error guide for the broader server-error troubleshooting sequence this error sits within, and the common hosting errors overview for how it compares to the other error families.
FAQ
Does this error mean my content is lost? Not necessarily. The error means the application can’t currently reach the database — the data is usually still intact once the connection or corruption issue is resolved, especially if caught quickly.
Why did this start right after I migrated to a new host?
This is the single most common trigger — the database host address or credentials weren’t updated to match the new server’s values. Check DB_HOST first in this scenario.
Can too much website traffic cause this error? Yes, indirectly. High traffic can exceed your plan’s simultaneous database connection limit, which produces this exact message even though nothing is technically broken.
Is running a database repair tool risky? Built-in CMS repair tools are generally low-risk and designed for exactly this situation, but always take a backup first if one exists and the site is currently reachable enough to create one.