Key takeaways
- Wrong credentials in wp-config.php cause most database connection errors.
- The database user must be assigned to the database with privileges.
- After migrating, update wp-config.php with the new database details.
This WordPress message means PHP is running but couldn’t connect to the MySQL or MariaDB database. Nothing on the site can load until it does.
1. Check the credentials in wp-config.php
Open wp-config.php in the WordPress root folder and compare these four values with the database in cPanel’s MySQL Databases:
define('DB_NAME', 'account_wpdb');
define('DB_USER', 'account_wpuser');
define('DB_PASSWORD', '…');
define('DB_HOST', 'localhost');
- On cPanel, database and user names are prefixed with your account name.
- If you’re unsure of the password, set a new one for the user in MySQL Databases and paste it into
wp-config.php. DB_HOSTislocalhoston most shared hosting.
2. Check the user has privileges
In MySQL Databases, under Current Databases, confirm the user is listed against the database. If not, add the user to the database with All Privileges.
3. Check the database server is running
If other sites on the same server also fail, the database server may be down or overloaded. On a VPS:
sudo systemctl status mariadb # or mysql
On shared hosting, contact support.
4. Repair corrupted tables
If the front end fails but /wp-admin shows a repair message, add this line to wp-config.php, visit /wp-admin/maint/repair.php, then remove the line:
define('WP_ALLOW_REPAIR', true);
5. After a migration
When you move a site, the database name, user and password usually change. Update wp-config.php with the new values and make sure you imported the database.