When viewing your website, if you encounter the "Error Establishing a Database Connection" message on your WordPress site, it represents a fatal error that renders your site inaccessible to viewers. This error occurs when a connection fails to the database, typically originating from the wp-config.php file or other related issues.
What does error establishing a database connection mean?
The underlying cause typically stems from incorrect database credentials entered in the configuration file, missing tables, or the database server refusing connection. Since WordPress is dynamically driven and stores substantial data within the database — called upon throughout pages, posts, plugins, and themes — it requires four specific elements: database name, database username, database password, and database host. If any of these fields contain errors, WordPress cannot establish a database connection. Users should verify accuracy multiple times, as typographical errors commonly trigger this issue.
Check Your WordPress Credentials
The most prevalent reason for encountering this error usually involves recently switching hosting providers. If you move to our managed WordPress hosting we do the migration and check the database connection before cutover.
How do I check my WordPress Configuration File?
Database details are stored in the wp-config.php file located in the root folder of your WordPress installation. When editing this file, you'll observe specific configuration lines. Cross-check the credentials entered against your MySQL database. For cPanel hosts, locate this information in the control panel under the 'Databases' heading, directing you to the database overview page displaying existing databases. Further down, you'll find the current users associated with your database. After confirming database name, username, password, and host (typically localhost, though this varies by hosting provider — contact your host if uncertain), you may change the database user password if needed, ensuring the updated password is used in wp-config.php's database password field. After completing these steps, revisit your site to verify the error has resolved.
Repair Your WordPress Database
If encountering the message "One or more database tables are unavailable. The database may need to be repaired" when visiting /wp-admin, it indicates a missing database table. Following site migration, tables may not have transferred during database export — double-check and obtain another export. However, you can repair the database by selecting the hyperlink on the page. Before repairing, add this line to wp-config.php:
define('WP_ALLOW_REPAIR', true);
Important Note: This page remains accessible without login, so remove that line from the config file after completing repairs.
Check If Your Database Host is Down
If previous troubleshooting steps haven't resolved connection issues, your MySQL host may be responsible. This typically occurs during high-traffic periods when servers cannot manage traffic volume, causing intermittent database connection problems. If maintaining multiple hosting accounts on the same server running WordPress, check whether they're experiencing similar issues. Next, contact your hosting provider or check their network status page for existing problems or direct assistance.
Finally
Snappyhost invites suggestions regarding this matter via email at [email protected] for potential blog post updates benefiting other users. Direct customers can contact Snappyhost, where technical experts will provide assistance.
Hosting that keeps up
Fast UK WordPress hosting, managed for you.
LiteSpeed with LSCache, NVMe SSD, staging and daily backups, with free migration from your current host.