How to fix Error establishing a database connection in WordPress from cPanel

Category: WordPress

The Error establishing a database connection message appears when your site cannot connect to the MySQL database it needs to load. On shared hosting, start by checking wp-config.php, the MySQL account and permissions from cPanel before changing plugins or themes.

Before you start

  • Have access to cPanel and File Manager.
  • Identify the folder where the site is installed, usually public_html.
  • Keep the database name, user and password ready if you saved them when installing the site.
  • Make a copy of the wp-config.php file before editing it.

Steps

  1. Open File Manager in cPanel and go to the site folder.
  2. Locate wp-config.php, download a copy and then open it with Edit.
  3. Check that DB_NAME, DB_USER, DB_PASSWORD and DB_HOST have complete values, without extra spaces or missing quotes.
  4. In cPanel, open MySQL Databases or Database Wizard and confirm that the database shown in DB_NAME exists.
  5. Check that the MySQL account shown in DB_USER exists and has privileges on that database.
  6. If you do not know the current password, create a new one for the MySQL user and update the same value in DB_PASSWORD inside wp-config.php.
  7. Save the file, reload the site in a private window and check whether it now loads without the error.

How to verify it is fixed

  • The site opens without showing Error establishing a database connection.
  • The wp-config.php file stores the same database name and user you see in cPanel.
  • The MySQL user appears assigned to the correct database.
  • The admin dashboard opens at /wp-admin without returning to the connection error.

Common errors

  • The error stays the same after saving → one credential is different between wp-config.php and cPanel → compare database name, user, password and host one by one.
  • cPanel shows the database but not the assigned MySQL account → that account does not have permissions on the database → assign it again with privileges from MySQL Databases.
  • The site changes to error 500 after editing → the wp-config.php syntax was damaged → restore the copy you downloaded and repeat the change carefully.

When to ask for help

If the credentials match and the error continues, there may be damaged tables, temporary MySQL connection limits or a server-side issue. In that case, share the error time, affected domain and that you already validated wp-config.php against cPanel with support.

Still need help?

If this guide didn’t solve your issue, our team can help you via ticket.