How to fix Error establishing a database connection in WordPress from cPanel
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.phpfile before editing it.
Steps
- Open File Manager in cPanel and go to the site folder.
- Locate
wp-config.php, download a copy and then open it with Edit. - Check that
DB_NAME,DB_USER,DB_PASSWORDandDB_HOSThave complete values, without extra spaces or missing quotes. - In cPanel, open MySQL Databases or Database Wizard and confirm that the database shown in
DB_NAMEexists. - Check that the MySQL account shown in
DB_USERexists and has privileges on that database. - If you do not know the current password, create a new one for the MySQL user and update the same value in
DB_PASSWORDinsidewp-config.php. - 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.phpfile 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-adminwithout returning to the connection error.
Common errors
- The error stays the same after saving → one credential is different between
wp-config.phpand 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.phpsyntax 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.
Recommended reading
Still need help?
If this guide didn’t solve your issue, our team can help you via ticket.