Skip to content
SazM Senior dev · Fixed price
Find a service
Where can I help?

Use arrow keys to browse, Enter to open, and Escape to close.

11 destinations

Client Login Get a fix →

Bug Fixing · 5 min read

Error Establishing a Database Connection: WordPress Fix in 48 Hours

Fix WordPress "Error establishing a database connection": test wp-config.php credentials, DB_HOST, MySQL memory crashes, grants and crashed tables with exact logs, SQL and WP-CLI commands.

Summary

"Error establishing a database connection" is WordPress telling you it cannot talk to MySQL or MariaDB. The whole site, front end and wp-admin, shows one plain white page. It is almost always one of four things: wrong credentials in wp-config.php, a database server that is down or out of memory, a host name that changed after a migration, or a corrupted database table.

This guide gives you the fast isolation steps first. If you would rather hand it over, SazM fixes this error for a fixed $99, delivered within 48 hours, entirely in writing: no calls, no project manager, one senior developer.

Where the Error Usually Lives

Check these before changing anything:

wp-config.php                                  # DB_NAME, DB_USER, DB_PASSWORD, DB_HOST
/var/log/mysql/error.log  or  /var/log/mariadb/mariadb.log
/var/log/nginx/error.log  or  /var/log/apache2/error.log
wp-content/debug.log                           # when WP_DEBUG_LOG is on

Typical lines and what they point to:

Access denied for user 'wp_user'@'localhost' (using password: YES)
  -> wrong DB_USER or DB_PASSWORD, or the user lost its grants

Unknown database 'wp_site'
  -> wrong DB_NAME, or the database was never imported after a migration

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
  -> MySQL is not running, or DB_HOST points at the wrong socket

Out of memory (Needed 4096 bytes)  /  mysqld got signal 9 (OOM killer)
  -> the server ran out of RAM and the database process was killed

Table './wp_site/wp_options' is marked as crashed and should be repaired
  -> a corrupted MyISAM table

Quick Fix Breakdown (DIY)

  • Test the credentials outside WordPress. Use the exact values from wp-config.php:
mysql -h localhost -u wp_user -p wp_site -e "SELECT 1;"

If this fails, the problem is the credentials, the grants or the server, not WordPress.

  • Check the database server is running.
systemctl status mysql        # or: systemctl status mariadb
sudo systemctl restart mysql
free -m                       # is memory exhausted?
dmesg | grep -i "killed process"

If mysqld keeps getting killed, the server needs more memory or a lower innodb_buffer_pool_size, not repeated restarts.

  • Check DB_HOST. Many hosts do not use localhost. Managed hosts give a separate host name, and a custom port is written as host:3307:
// wp-config.php
define('DB_HOST', 'localhost');
  • Fix a mismatched grant (use the least privileges your host allows, and confirm the user and password first):
SHOW GRANTS FOR 'wp_user'@'localhost';
GRANT ALL PRIVILEGES ON wp_site.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
  • Let WordPress repair tables (after a backup). Run mysqldump wp_site > backup.sql first if the server is up. Then add this line to wp-config.php, visit /wp-admin/maint/repair.php, then remove the line again because that page needs no login while it is enabled:
define('WP_ALLOW_REPAIR', true);

From the command line, wp db repair and wp db check do the same job.

  • Check the siteurl rows after a migration. wp option get siteurl and wp option get home must match the live domain.
  • Look for a connection limit. On busy shared hosting, Too many connections in the MySQL log means another site or a runaway plugin is using all the slots:
SHOW VARIABLES LIKE 'max_connections';
SHOW STATUS LIKE 'Threads_connected';

If none of these isolates it within an hour, stop. Every extra hour of guessing is lost traffic and lost orders.

Hand It Over: $99 Fixed, Within 48 Hours

Most database connection errors are quick to fix once someone reads the right log. They drag on because the site owner, the host and the plugin vendor each point at someone else. One developer who reads the logs, finds the root cause and fixes it ends that.

What you get for $99:

  • A fixed price agreed before work starts. One issue, one flat fee, no hourly meter.
  • Delivery within 48 hours of access, with the fix verified before anything is declared done.
  • Fully written, fully async. You send the site URL, the error and when it started. You get questions, progress and proof in writing. There are no calls, meetings or project managers in between, so your time zone does not matter.
  • Written proof it works: the root cause in plain language, what changed, a before and after check, and a rollback note.
  • Money-back guarantee if the agreed root cause cannot be resolved.
  • Safe access only: a separate admin or SSH account and a fresh backup first. Never send passwords through the inquiry form.

Behind it: 20+ years in production (since Oct 2006) and 100+ projects in the portfolio.

Get this error fixed for $99 → · Queue an urgent fix · See past projects

If the site is also slow after it comes back, the $199 Core Web Vitals fix can be done in the same window.

Frequently Asked Questions

What causes "Error establishing a database connection" in WordPress?

WordPress cannot reach or log into its database. The usual causes are wrong credentials or DB_HOST in wp-config.php, a stopped or memory-starved MySQL server, missing grants, or a corrupted table.

Why does only wp-admin show a database error, or only the front end?

If wp-admin shows "One or more database tables are unavailable", a table is corrupted; run wp db repair. If only the front end fails, check for a connection limit or a caching drop-in that is misconfigured.

How do I fix it without losing data?

Take a backup of the database files or run mysqldump first when the server is up. Credential, host and grant fixes do not touch your data. Only repair operations modify tables, so back up before running them.

How much does it cost to fix this error?

SazM fixes one issue for a fixed $99, delivered within 48 hours, with a money-back guarantee if the agreed root cause cannot be resolved. Everything is handled in writing.

Do I need a call to explain the problem?

No. Send the site URL, the exact error text and what changed recently, such as a migration, a host change or a plugin update. A written report is more precise than a call.

// SazM ENGINEERING DISPATCH · PRODUCTION REMEDIATION

Senior Engineering Without Agency Overhead

// TRACK A · FIXED-PRICE FIXES (48H SLA)

Single Urgent or Speed Fix

Immediate code-level fixes with zero discovery calls. Emergency root-cause patch within 48 hours for $99, or full Core Web Vitals & speed remediation with before/after audit for $199. 100% money back if the agreed root cause cannot be fixed.

Running WordPress or WooCommerce? The WordPress care plan keeps your site updated, hardened, backed up daily, and monitored for $49/mo.

// TRACK B · SENIOR RETAINER & BUILDS

Monthly Plan or Custom Scope

Direct senior-level capacity embedded in your stack. Dedicated monthly engineering ($999/mo, 1 active task at a time, 24–48h PR delivery, pause or cancel anytime), or fixed-scope architectural milestones delivered within a 24h written quote.

✓ 20+ years engineering ✓ 100+ projects in the portfolio ✓ Fixes within 48 hours ✓ 100% money back if not fixed
1 Active Task at a Time
Requests are completed one by one in your priority order. As soon as an active task is shipped, tested, and approved, work starts immediately on your next task within our 24–48h SLA.
48h Emergency SLA
Clock starts as soon as site access details are provided. Delivered with full backup taken first, isolated staging testing, and 100% money back if not fixed.
WordPress Care Plan Scope
Weekly core and plugin updates pre-tested in staging, daily offsite encrypted backups, 24/7 uptime monitoring, and proactive security patching.
Pay Nothing Upfront
Zero upfront payment or credit card required. A 20-Year Senior Engineer diagnoses your issue, reproduces it on isolated staging, and deploys the fix. You only pay once you verify the staging reproduction or production fix.