Error establishing a database connection — WordPress fix that actually works
Quick answer
"Error establishing a database connection" means WordPress can't reach your MySQL/MariaDB database. Four causes account for 95% of cases: (1) wrong DB credentials in wp-config.php, (2) the database server is down or over quota, (3) the site is over its host's connection limit from a traffic spike or attack, or (4) a database table is corrupted. Fix in this order: verify wp-config credentials, check the host status page, then run WordPress's built-in database repair.
What this error actually means
WordPress stores every post, page, user, setting, and comment in a MySQL or MariaDB database. Every page load makes 20 to 200 database queries. When WordPress tries to open that connection and gets refused, it can't render anything, so it shows this bare white page with the error string.
The connection failure is almost always one of four things. Work through them in order — the cheap checks first.
Cause #1 — Wrong wp-config credentials (most common after migration)
Open wp-config.php via SFTP or your host's File Manager. Find the four lines that define DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. These have to match exactly what your host set up.
If you recently migrated hosts, restored a backup, or someone rotated the database password — this is your problem 90% of the time. Log into your host control panel (cPanel → MySQL Databases, or MyKinsta → Info, or SiteGround → Site Tools → MySQL), copy the current DB name, username, and host, and update wp-config.php.
The DB_HOST value is not always 'localhost'. Managed hosts like Kinsta, WP Engine, and SiteGround use a specific hostname like 'us-east4-001.mysql.database.yourhost.com'. Copy exactly, no typos, no trailing whitespace.
Save and reload. If the credentials were the problem, the site comes back immediately.
Cause #2 — The database server is down or over quota
If the credentials are correct and the site still shows the error, the database itself might be unreachable. Two checks.
Host status page: Search "[your host name] status" — hosts publish real-time status. If they're in the middle of a MySQL outage, you're not fixing this from your end. Wait it out.
Database quota: Cheap shared hosts cap the database size (often 1GB) or the number of concurrent connections (often 25). If you hit either, MySQL rejects new connections. Log into your host, check the database usage, and if you're over quota either upgrade the plan or clean up. WP-Optimize or Advanced Database Cleaner can reduce the DB size by clearing spam, revisions, and transients.
Prefer we just fix it?
Site is down or blocking real customers right now? Our emergency team is live around the clock — median response 12 minutes, flat $149 for the fix. Learn more about emergency WordPress help or grab a slot below.
Cause #3 — Traffic spike or brute-force attack maxing out connections
If the site was fine an hour ago and just started throwing the error, check for a traffic spike. Legitimate spike (viral post, ad campaign) or malicious (brute force against wp-login.php, XML-RPC flood) both look the same to MySQL: too many connections.
Quick check: look at your host's request log or Cloudflare analytics for the last hour. If wp-login.php or xmlrpc.php has thousands of hits, you're under attack.
Fix: put Cloudflare in front of the site (free plan is fine), enable "Under Attack Mode" for 15 minutes, then set a rate-limit rule on /wp-login.php (10 requests per minute per IP). The connection pressure drops instantly and MySQL recovers.
Cause #4 — A corrupted database table
Rare but real. If a specific page throws the error and others don't, or the error is intermittent, a table might be corrupt.
WordPress has a built-in repair tool. Edit wp-config.php and add 'define("WP_ALLOW_REPAIR", true);' above the '/* That's all, stop editing! */' line. Then visit yoursite.com/wp-admin/maint/repair.php in a browser. Click "Repair Database" (or the safer "Repair and Optimize" if you have time).
When done, remove the define line immediately — leaving that page publicly accessible is a security hole. Save wp-config.php and reload.
When to stop DIY-ing and call an engineer
If wp-config credentials look right, the host status is green, there's no traffic anomaly, and the repair tool still shows corruption — the fix is probably restoring the database from a backup, and that is not something to guess at with a live store or lead-gen site.
WebCare Studios does emergency database recoveries from $149 including a full point-in-time restore where possible. Median first response is 11 minutes. If the site has been down more than 15 minutes and you'd rather have an engineer just fix it, book the emergency slot below.
Common questions
What does error establishing a database connection mean?+
WordPress cannot reach the MySQL or MariaDB database that stores your content and settings. The cause is almost always one of: incorrect database credentials in wp-config.php (common after migration), the database server being down, the site exceeding its host's connection or storage quota, or a corrupted database table.
How do I fix error establishing a database connection in WordPress?+
In order: (1) verify DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in wp-config.php match your host's current values, (2) check your host's status page for a MySQL outage, (3) check your database quota and connection limits, (4) if only some pages fail, enable WP_ALLOW_REPAIR in wp-config.php and visit /wp-admin/maint/repair.php.
Can I still log in to WordPress with a database connection error?+
No. WordPress needs the database for every request, including the login page. You'll see the same error string on wp-admin as on the front-end. Fix wp-config.php or the underlying MySQL issue first — you can only log in once the database is reachable again.
How do I find WordPress database credentials?+
For an existing site, they are already in wp-config.php on lines defining DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. To confirm they still match the server, log into your host's control panel: cPanel → MySQL Databases, MyKinsta → Info tab, SiteGround → Site Tools → MySQL, or your managed host's equivalent. Values must match exactly, including no trailing whitespace.
Does high traffic cause the database connection error?+
Yes. Every WordPress page load opens a database connection, and shared/managed hosts cap the number of concurrent connections (often 25 to 100). A traffic spike or brute-force attack against wp-login.php or xmlrpc.php can saturate the limit and cause MySQL to reject new connections. Put Cloudflare in front of the site and rate-limit /wp-login.php to fix it.
Want help with this?
The pages below go deeper, by service and by city.
Want this handled for you?
Book a call and we will review your site before recommending anything.