Knowledge Base

How to Fix an Error Establishing a Database Connection

This article will show you how to fix an error establishing a database connection.

This message means your site loaded but could not reach its database. The cause is nearly always the credentials, the database server itself, or a corrupted table.


1. Check the Database Credentials

Your site stores a database name, user, password and host in its configuration file. On WordPress that is wp-config.php. Compare each value against the database as it exists in your control panel. A password reset that was never copied across is the most common cause.

2. Confirm the Database User Has Access

A user can exist without being attached to the database, which fails in exactly this way. In your control panel, check the user is assigned to the database with full privileges.

3. Check the Database Host

On most shared hosting this is localhost, but not always. If your host uses a separate database server, the name must match exactly.

4. Repair the Database

A table can be marked as crashed after an unclean shutdown. Use the repair option in phpMyAdmin, or on WordPress add define('WP_ALLOW_REPAIR', true); to wp-config.php and visit /wp-admin/maint/repair.php. Remove the line afterwards.

5. Check Whether You Are Over Quota

If the account has hit its disk limit, the database cannot write and connections fail. Your control panel shows current usage.

6. Contact Support if the Database Is Unreachable

If the credentials are right and the database still will not respond, the database server may be down. Open a ticket rather than changing more settings.


Next: Why You Should Take Regular Backups covers the backups that make a bad database recoverable.

Please rate this article to help us improve our Knowledge Base.

0 0