"Error establishing a database connection" on WordPress: what it means and how to fix it

Your whole WordPress site shows one line of text: Error establishing a database connection. Your posts and pages are almost certainly safe. WordPress cannot reach the database that holds them.

The usual causes, most common first

  1. The database server is down or overloaded. Common on cheap shared hosting during traffic spikes. Wait ten minutes and reload. If it keeps happening, ask your host whether you hit a connection limit.
  2. Wrong login details in wp-config.php. This happens after a move to a new host or a password change. Open wp-config.php and compare DB_NAME, DB_USER, DB_PASSWORD and DB_HOST with what your hosting panel shows under Databases. DB_HOST is often localhost but not on every host.
  3. A corrupted table. If only the admin shows a different error, add define('WP_ALLOW_REPAIR', true); to wp-config.php, visit /wp-admin/maint/repair.php, run the repair, then remove the line.
  4. The disk is full. A full disk stops the database from writing. Check disk usage in your hosting panel.

Before you change anything

Download a copy of wp-config.php first. If you ask your host for help, tell them the exact message and the time you first saw it. It is one of the most common WordPress failures, and support desks fix it daily.


Want the rest of your site checked after it is back? Run a free 40-point check at tinkeraudit.com.