Before you start
- Control panel access, or SSH
- Access to wp-config.php
Step 1: Check /wp-admin as well as the homepage
If /wp-admin says one or more database tables are unavailable and the database may need to be repaired, WordPress connected but found damaged tables — skip to the repair step. If it shows the same connection error, the credentials or the database server are the problem.
Step 2: Compare wp-config.php with the panel
DB_NAME, DB_USER, DB_PASSWORD and DB_HOST must match a real database and user. On cPanel, MySQL Databases lists both and shows whether the user is added to that database. After a migration, a wrong name prefix or a user never added to the database is the usual cause.
define( 'DB_NAME', 'cpuser_wp' ); define( 'DB_USER', 'cpuser_wpuser' ); define( 'DB_PASSWORD', '…' ); define( 'DB_HOST', 'localhost' );Step 3: Reset the password if unsure
cPanel cannot show you a database user's password, only change it. Set a new one in MySQL Databases, then paste the same value into DB_PASSWORD. DB_HOST is localhost on most cPanel servers; a site moved from another host may still carry that host's value.
Step 4: Test the credentials directly
Over SSH, connect with the same details. Access denied means the user, password or privileges are wrong. Can't connect to the server means the database service itself is not answering — report that exact message to your host, as there is nothing to fix in WordPress.
mysql -u cpuser_wpuser -p -h localhost cpuser_wp # or, using wp-config.php's own values: wp db checkStep 5: Repair damaged tables
Add the line below to wp-config.php, open /wp-admin/maint/repair.php and run Repair Database. Remove the line as soon as it finishes.
define( 'WP_ALLOW_REPAIR', true );Step 6: Look for a resource limit
If the error comes and goes under traffic, the account may be hitting its database connection or memory limits. The error log in the control panel shows when it happens; caching pages reduces how many requests reach the database at all.
The mistake people make
Leaving WP_ALLOW_REPAIR in wp-config.php. The repair page does not require a login, so anyone who finds it can run repairs and optimisations against your database whenever they like.
