Choose a plan

“Error establishing a database connection”

Your site shows “Error establishing a database connection”? Check the database, user and password from wp-config.php in Enhance, step by step.

  • Updated
guide · common errors
Steps
13
Reading time
4min
Sections
4
Start the guide

The “Error establishing a database connection” message means the website can't access its database. The website's files are in place, but the connection details don't match: the database name, the user, the password or the server. It often appears after a move, after a partial restore or after someone changed the database user's password.

What you'll achieve

  • compare the details in the website's settings with the database in Enhance;
  • restore the connection, with a new password for the user;
  • know what to do if the database is missing or empty.

Before you start

  • Log in to Enhance at https://server.nbt-host.com, then “Websites” » your website.
  • The steps are written for WordPress, where the connection details are in wp-config.php. In other applications the file has a different name (for example configuration.php or .env), but the idea is the same.

The steps

1. Read the details in wp-config.php

  1. The “Files” tab » public_html, right-click wp-config.php » “Edit”.
  2. Write down these four lines:
define( 'DB_NAME', 'numele_bazei' );
define( 'DB_USER', 'utilizatorul' );
define( 'DB_PASSWORD', 'parola' );
define( 'DB_HOST', 'localhost' );
  1. Close the file without saving anything, for now.

2. Compare with what's in Enhance

  1. Open the website's “Databases” tab.
  2. Check that:
    • the database named in DB_NAME is in the list;
    • the user in DB_USER exists on the “Users” tab, next to “Databases”, and has access to that database;
    • the server in DB_HOST is localhost.
  3. Database and user names have a prefix added by Enhance, for example site_abc1_magazin. In wp-config.php they must be written in full, including the prefix. You can see the exact details on the database page, under “Connection info” (see Creating a MySQL database and user).

3. Set a new password for the user and enter it in wp-config.php

No one can see the old password, not even us. The safest option is to set a new one, in both places:

  1. In the “Users” tab, next to “Databases”, open the database user, set a new password (the key button generates a long one) and copy it.
  2. Back in “Files”, open wp-config.php with “Edit” and enter the new password in DB_PASSWORD, between the single quotes.
  3. If needed, also correct DB_NAME, DB_USER and DB_HOST.
  4. Save and reload the website.

If the user no longer exists (for example, after restoring only some databases), create it again with “Add user”, tick the database under “Database access” and enter its details in wp-config.php.

4. The database is missing or empty

  • The database isn't in the list. If you moved the website, create it and import the .sql file from your old hosting with “Import SQL file” (see Creating a MySQL database and user). If it was deleted by mistake, restore it from the “Backups” tab (see Backup and restore from Enhance).
  • The database is there, but the website asks you to install WordPress from scratch. The database is empty or the tables have a different prefix than $table_prefix in wp-config.php (usually wp_). Check the table prefix in the .sql file and set the same prefix in wp-config.php.

If something doesn't work

  • The error appeared after a restore. If you restored only some databases, their users are not recreated. Restore all the databases or recreate the user, as in step 3.
  • The error comes and goes. The details are correct, but the database server or the website is under heavy load. Send us the time when it appears.
  • The WordPress dashboard says the database needs to be repaired. First make a copy (the “Backups” tab » “Create backup”), then write to us: we'll check the tables.
  • I don't want to touch wp-config.php. Send us the domain and we'll do the check for you.
Support

Stuck? We'll do it together.

Tell us which step isn't working and, if you can, send a screenshot. We reply during business hours.

Phone and WhatsApp+40 775 396 021
HoursMonday–Friday, 9:00–18:00 Romanian time (EET/EEST)

Never send us your password on WhatsApp or by email. What information helps us solve it on the first try: how to ask for help.