"Error establishing a database connection" means WordPress cannot connect to its MySQL/MariaDB database. This is usually caused by incorrect credentials in wp-config.php, a down database server, or a corrupted database.
Wrong database credentials in wp-config.php
Open wp-config.php in cPanel File Manager and verify DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST (should be localhost). Then check cPanel > MySQL Databases to confirm the database and user exist and the user is assigned to the database.
01. Check wp-config.php Credentials
Open wp-config.php in your WordPress root directory and find these lines:
define('DB_NAME', 'username_dbname');
define('DB_USER', 'username_dbuser');
define('DB_PASSWORD', 'yourpassword');
define('DB_HOST', 'localhost');
Remember that on cPanel, database names and usernames are prefixed with your cPanel username (e.g., cpuser_wordpress). See Cannot Connect to MySQL for detailed troubleshooting.
02. Verify Database User Permissions
- cPanel > MySQL Databases
- Scroll to "Current Databases" - Verify your database is listed
- Check "Privileged Users" column - Your DB user must be listed
- If not assigned, add the user under "Add User To Database" with All Privileges
See How to Add a User to a Database.
03. Repair the Database
If credentials are correct but the database is corrupted, add this to wp-config.php temporarily:
define('WP_ALLOW_REPAIR', true);
Then visit yourdomain.com/wp-admin/maint/repair.php and click "Repair Database." Remove the line from wp-config.php when done.
04. Database Server Down
If everything checks out but you still see the error, the MySQL/MariaDB service may be temporarily down. Test with our MySQL Connection Test. If the server is down, open a ticket immediately.
Database Issues?
Open a Support TicketQuick Recap
- Check wp-config.php credentials - DB_NAME, DB_USER, DB_PASSWORD, DB_HOST
- Verify user is assigned to the database in cPanel > MySQL Databases
- DB_HOST should be localhost on shared hosting
- Use WP_ALLOW_REPAIR for database corruption
- Contact support if the database server is down
WordPress database troubleshooting · Last updated March 2026 · Browse all WordPress articles
