“Error establishing a database connection” in WordPress

Fix WordPress’s database connection error: check wp-config.php credentials, database user permissions, the database host and damaged tables.

Guide2 min readLast updated
On this page
  1. Does this match what you’re seeing?
  2. 1. The details in wp-config.php
  3. 2. The password
  4. 3. The user’s access to the database
  5. 4. Damaged tables
  6. Still failing?

Does this match what you’re seeing?

  • Every page shows ‘Error establishing a database connection’
  • The error appeared after moving host or changing a password

WordPress can’t log in to its database. The cause is nearly always one of four things.

1. The details in wp-config.php

Open wp-config.php in System Info & Files › File Manager and find:

define('DB_NAME', 'username_wp123');
define('DB_USER', 'username_wpuser');
define('DB_PASSWORD', '...');
define('DB_HOST', 'localhost');

Compare with Account Manager › MySQL Management:

  • Database and user names include your account prefix, for example username_wp123. Missing the prefix is the most common mistake after a migration.
  • DB_HOST should be localhost.

2. The password

If you’re unsure the password is right, set a new password for the database user in Account Manager › MySQL Management and put the same password in DB_PASSWORD. How to change a database user’s password

3. The user’s access to the database

In Account Manager › MySQL Management, open the database and check the user is listed with privileges. If not, add the user to the database with all privileges. Managing database users and privileges

4. Damaged tables

If the front end shows the error but /wp-admin says tables need repair, add this to wp-config.php:

define('WP_ALLOW_REPAIR', true);

Visit /wp-admin/maint/repair.php, run the repair, then remove the line. How to repair and optimise database tables

Still failing?

If the credentials are definitely correct, check the status page for a database service problem, then report it through the contact form (choose “Something only Traxio can do”).

Prefer to follow along?

Everything in this guide works on Traxio’s WordPress hosting: £0.99 a month.

Spotted something out of date or unclear? Tell us and we’ll fix it.

Keep going