Skip to content

Help Centre › Websites, files and databases

How do I fix "Error establishing a database connection"?

WordPress can’t log in to its MySQL database. Usually the database name, username or password in wp-config.php doesn’t match what is in cPanel, or the user was never added to the database, so check those first.

  1. In File Manager, open public_html, select wp-config.php and click Edit. Note the values of DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Copy the file first so you can undo any change.
  2. In cPanel, open Databases → MySQL Databases. The database and user names include your account prefix, such as account_wp. The names in wp-config.php must match exactly, prefix included.
  3. Under Current Databases, check the user is listed under Privileged Users for that database. If not, use Add User To Database, choose both, tick ALL PRIVILEGES and click Make Changes.
  4. Still failing? Under Current Users, click Change Password next to the user and set a new password. Put exactly the same password in DB_PASSWORD and save the file.
  5. Make sure DB_HOST is localhost.
  6. Reload the site.

Tip: Avoid single quotes and backslashes in the database password. They break the line in wp-config.php and cause this exact error.

If the details are all correct

  • Just moved the site? Open Databases → phpMyAdmin and click the database. If it has no tables, the import didn’t happen. Import your .sql file: see How do I import or export a database with phpMyAdmin?
  • Damaged tables. If the dashboard says the database needs repairing, add define('WP_ALLOW_REPAIR', true); to wp-config.php, open yourdomain.com/wp-admin/maint/repair.php and click Repair Database. Remove the line afterwards: anyone can open that page while it is there.
  • Every site on your account has the error at once and you changed nothing: the database server may be down. Open a ticket marked urgent.

Other applications work the same way: Joomla keeps its database details in configuration.php, and most other apps have a similar settings file.

Still stuck? Open a support ticket with your domain and when the error started (never your passwords), or message us on WhatsApp.

Updated 6 November 2026. Something here out of date? Tell us.

Ask us on WhatsApp