## 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:

```text
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:

```text
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`:

```bash
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.**

```bash
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`:

```php
// 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):

```sql
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:

```php
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:

```sql
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 →](/bug-fix-services)** · [Queue an urgent fix](/checkout/emergency) · [See past projects](/projects)

If the site is also slow after it comes back, the $199 [Core Web Vitals fix](/articles/core-web-vitals-inp-lcp-remediation) 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.
