Knowledgebase article

How to fix "Error establishing a database connection" in WordPress

Your website and its database have stopped talking to each other. Every lovers' quarrel has a cause, and here it's almost always the login details in wp-config.php.

1. Check the details in wp-config.php

  1. In cPanel, open File Manager and go to public_html (or your WordPress folder).
  2. Right-click wp-config.php and choose Edit.
  3. Find these lines:
define( 'DB_NAME', 'cpaneluser_wp123' );
define( 'DB_USER', 'cpaneluser_wp123' );
define( 'DB_PASSWORD', '........' );
define( 'DB_HOST', 'localhost' );
  1. Go to Databases > Manage My Databases and compare:
    • Does a database with exactly that DB_NAME exist (including the cpaneluser_ prefix)?
    • Does a user with exactly that DB_USER exist?
    • Is that user listed under Privileged Users for the database?
    • DB_HOST should be localhost.

2. Reset the database user's password

If you're not sure the password is right:

  1. In Manage My Databases, scroll to Current Users and click Change Password next to the user.
  2. Set a new password and click Change Password.
  3. Put the same password in DB_PASSWORD in wp-config.php and click Save Changes.

3. Make sure the user has privileges

Under Add User To Database, choose the user and database, click Add, tick ALL PRIVILEGES and click Make Changes.

4. Just moved your site?

If you imported the site from another host, the database name and user will be different at Romeo. Update all four lines in wp-config.php with your new details.

5. Database damaged?

In Manage My Databases, choose your database under Repair Database and click Repair Database.

Still not talking?

If the details are all correct and the error stays, the database server may be busy. Check Network Status, then open a ticket. Romeo will bring them back together.

Was this answer helpful?

Related articles

Still stuck? Romeo's got you.
Our support team replies around the clock, real humans who know your server.