What causes the error
WordPress reads its database details from wp-config.php on every page load. If one is wrong, or the database cannot answer, the site stops with this message.
- A wrong value in
wp-config.php:DB_NAME,DB_USER,DB_PASSWORDorDB_HOST. - A database user that is not added to the database, or has no privileges on it.
- Damaged (corrupted) database tables.
- A database server that is down or overloaded.
- A site moved to new hosting while
wp-config.phpstill has the old details.
Check wp-config.php in cPanel
Most cases end here. Compare the four values with what cPanel lists. What each line does: wp-config.php explained.
- Sign in to cPanel and open File Manager.
- Open the folder WordPress is in, usually
public_html. - Download a copy of
wp-config.php, so you can undo a change. - Edit
wp-config.phpand noteDB_NAME,DB_USER,DB_PASSWORDandDB_HOST. - Open cPanel › Manage My Databases (MySQL Databases in older cPanel) and check that the database and user names match exactly, including the prefix cPanel adds, such as
username_. - Set
DB_HOSTtolocalhost, the usual value on cPanel, unless your host gives you another. - Save the file and reload your site.
Check the database user
If the names match, reset the user’s password and its access to the database.
- In Manage My Databases, under Add User To Database, choose the user and the database, then click Add.
- Tick All Privileges and click Make Changes.
- Under Current Users, click Change Password next to the user and set a new password. Leave out
'and\, which can breakwp-config.php. - Paste the new password into
DB_PASSWORDinwp-config.phpand save. - Open phpMyAdmin in cPanel and click the database. If its tables are listed, such as
wp_options, your data is there. If the list is empty, restore a backup.
Repair the WordPress database
Damaged tables cause the same error on the site. The admin area often says more.
- Back up the database first: open phpMyAdmin, choose the database, click Export and save the file.
- Open
/wp-adminon your site. If it says “One or more database tables are unavailable”, the tables need a repair. - Add
define( 'WP_ALLOW_REPAIR', true );towp-config.php, above the “stop editing” comment. - Go to
/wp-admin/maint/repair.phpand click Repair Database. - Remove the line from
wp-config.phpwhen it finishes. The repair page needs no sign-in while it is there. - Or repair it in cPanel: in Manage My Databases, under Modify Databases, choose the database and click Repair Database.
Restore a backup or contact your host
If the values are right and a repair does not help, the database itself or the server is the problem.
- Export the current database in phpMyAdmin, so you can undo the restore.
- Restore the database from a backup made before the error started. Changes made since that backup are lost.
- If you moved the site, import its database at the new host and put the new details in
wp-config.php. - If the error comes and goes, or other sites on the account show it too, the database server may be down or overloaded. Open a support ticket with your host.
- If the site shows “There has been a critical error on this website” instead, see how to fix a WordPress critical error.
WordPress hosting with 30-day backups
HostUpIndia WordPress hosting keeps daily backups for 30 days, so you can restore a database from before the error. WordPress comes pre-installed on LiteSpeed, with NVMe storage, cPanel and free SSL.
From ₹149 a month on 3-year billing. Prices exclude 18% GST. See WordPress hosting plans.
- Support tickets and email are received 24 hours a day, 7 days a week.
- Free website migration by our in-house team.
- More help guides.
