Troubleshooting the 'Error Establishing a Database Connection' in WordPress
Content
One of the most common and alarming errors for any WordPress user is the sudden appearance of the "Error establishing a database connection" message. This error completely halts your site, preventing both visitors and you, the administrator, from accessing it. This guide will walk you through what this error means, its common causes, and the steps you can take to resolve it.
What Does This Error Mean?
At its core, this error means that the WordPress software running on your server is unable to communicate with the MySQL or MariaDB database where all your crucial content, settings, and user data is stored. Without this connection, your website cannot function.
Common Causes of the Database Connection Error
Based on community reports and troubleshooting threads, this error typically occurs for one of a few key reasons:
- Incorrect Database Credentials: The username, password, database name, or host address in your
wp-config.phpfile are wrong. This is the most frequent cause. - Database Server Unavailable: The database service on your server (e.g., MySQL) has crashed or is not running.
- Corrupted Database: The database itself has become corrupted, often due to an incomplete update or a server crash.
- Server Resource Issues: The server hosting your database has run out of disk space or memory, preventing it from operating correctly.
- Host-Specific Problems: Your web host may have temporarily suspended your account or is experiencing an outage on their end.
Step-by-Step Troubleshooting Guide
1. Check Your Database Credentials
The first and most important step is to verify the information in your wp-config.php file. You will need to access your site's files using an FTP client, SFTP, or your hosting provider's file manager.
- Locate the
wp-config.phpfile in the root directory of your WordPress installation. - Check the following lines and ensure they exactly match the database connection details provided by your web host:
define( 'DB_NAME', 'database_name_here' ); define( 'DB_USER', 'username_here' ); define( 'DB_PASSWORD', 'password_here' ); define( 'DB_HOST', 'localhost' ); // (or another host specified by your provider) - A single typo here will cause the connection to fail. If you are unsure of the correct credentials, you must contact your web hosting provider's support team to confirm them.
2. Contact Your Web Host
If your credentials are correct, the problem is likely on the server side. Before proceeding with more advanced troubleshooting, it is highly recommended that you contact your hosting provider. They can quickly check:
- If the MySQL database service is running.
- If your account is active and not suspended.
- If the server has enough disk space and memory. An error message containing phrases like "
Errcode: 28" or "No space left on device" is a clear indicator of a full disk, which only your host can resolve. - If there is a wider server outage affecting your site.
3. Check if the Database Service is Running (For Localhost Users)
If you are running WordPress on a local server stack like XAMPP, WAMP, or Local by Flywheel, the database software (MySQL/MariaDB) may have stopped.
- Open your local server's control panel (e.g., the XAMPP Control Panel).
- Ensure that the "MySQL" or "Database" module is started. If it is stopped, try starting it again.
4. Repair a Corrupted Database
WordPress has a built-in feature to attempt to repair a corrupted database. To use it, add the following line to your wp-config.php file:
define( 'WP_ALLOW_REPAIR', true );
After adding this line, visit the following URL in your browser: https://yourdomain.com/wp-admin/maint/repair.php
Important Security Note: Remember to remove this line from your wp-config.php file after you have finished the repair process.
5. Restore from a Backup
If the database is severely corrupted and cannot be repaired, your best course of action is to restore it from a recent backup. Most reputable hosting providers offer regular backups you can restore from their control panel. If you manage your own backups, you can use a tool like phpMyAdmin to import your backup file.
Conclusion
The "Error establishing a database connection" can be stressful, but it is almost always solvable. The process almost always begins with double-checking your wp-config.php credentials and then contacting your web host to investigate server-side issues. For users on localhost, ensuring your database service is running is the key first step.
Related Support Threads Support
-
Unable to turn off email notification in Ultimate Memberhttps://wordpress.org/support/topic/unable-to-turn-off-email-notification-in-ultimate-member/
-
How to resolve error while duplicating website?https://wordpress.org/support/topic/how-to-resolve-error-while-duplicating-website/
-
Word Press denied access emailhttps://wordpress.org/support/topic/word-press-denied-access-email/
-
cant log inhttps://wordpress.org/support/topic/cant-log-in-255/
-
Plugin could not be activated because it triggered a fatal error.https://wordpress.org/support/topic/plugin-could-not-be-activated-because-it-triggered-a-fatal-error-643/
-
Local host install errohttps://wordpress.org/support/topic/local-host-install-erro/
-
Warning: mysqli_real_connect(): (HY000/2002): Connection refused in /home/novelhhttps://wordpress.org/support/topic/warning-mysqli_real_connect-hy000-2002-connection-refused-in-home-novelh/
-
ошибка входа на сайтhttps://wordpress.org/support/topic/%d0%be%d1%88%d0%b8%d0%b1%d0%ba%d0%b0-%d0%b2%d1%85%d0%be%d0%b4%d0%b0-%d0%bd%d0%b0-%d1%81%d0%b0%d0%b9%d1%82/
-
Fatal error: Uncaught Error:https://wordpress.org/support/topic/fatal-error-uncaught-error-18/
-
meetup widgethttps://wordpress.org/support/topic/meetup-widget/
-
OAuth2 token is invalidhttps://wordpress.org/support/topic/oauth2-token-is-invalid/
-
Parse error: syntax error, unexpectedhttps://wordpress.org/support/topic/parse-error-syntax-error-unexpected-219/
-
Fatal Error, can’t get log into Dashboardhttps://wordpress.org/support/topic/fatal-error-cant-get-log-into-dashboard/
-
[NSFW] Error establishing a database connectionhttps://wordpress.org/support/topic/error-establishing-a-database-connection-963/
-
Editör beklenmeyen bir hata ile karşılaştıhttps://wordpress.org/support/topic/editor-beklenmeyen-bir-hata-ile-karsilasti/
-
mystorehttps://wordpress.org/support/topic/mystore-2/
-
Customize Feature Not Workinghttps://wordpress.org/support/topic/customize-feature-not-working-2/
-
WordPress could not establish a secure connection to WordPress.org. Please contahttps://wordpress.org/support/topic/wordpress-could-not-establish-a-secure-connection-to-wordpress-org-please-conta-3/
-
Error Message Jetpack Contact Formhttps://wordpress.org/support/topic/error-message-jetpack-contact-form/
-
There has been a critical error on your website. Please check your site admin emhttps://wordpress.org/support/topic/there-has-been-a-critical-error-on-your-website-please-check-your-site-admin-em-11/
-
PHP PROBLEM…https://wordpress.org/support/topic/php-problem-21/
-
theme customizing problemhttps://wordpress.org/support/topic/theme-customizing-problem/
-
not access to inter localhosthttps://wordpress.org/support/topic/not-access-to-inter-localhost/
-
只今メンテナンス中です。しばらくお待ちください。https://wordpress.org/support/topic/%e5%8f%aa%e4%bb%8a%e3%83%a1%e3%83%b3%e3%83%86%e3%83%8a%e3%83%b3%e3%82%b9%e4%b8%ad%e3%81%a7%e3%81%99%e3%80%82%e3%81%97%e3%81%b0%e3%82%89%e3%81%8f%e3%81%8a%e5%be%85%e3%81%a1%e3%81%8f%e3%81%a0%e3%81%95/
-
An unexpected error occurred. Something may be wrong with WordPress.org or thishttps://wordpress.org/support/topic/an-unexpected-error-occurred-something-may-be-wrong-with-wordpress-org-or-this-19/
-
/wp-includes/functions.php on line 7161https://wordpress.org/support/topic/wp-includes-functions-php-on-line-7161/
-
500 POST error http://127.0.0.1/wordpress/wp-admin/admin-ajax.php 5 when makinghttps://wordpress.org/support/topic/500-post-error-http-127-0-0-1-wordpress-wp-admin-admin-ajax-php-5-when-making/
-
ログイン画面にてログインするとダッシュボードへ行かずサイトが表示され且つログインできていない状態に。https://wordpress.org/support/topic/%e3%83%ad%e3%82%b0%e3%82%a4%e3%83%b3%e7%94%bb%e9%9d%a2%e3%81%ab%e3%81%a6%e3%83%ad%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%99%e3%82%8b%e3%81%a8%e3%83%80%e3%83%83%e3%82%b7%e3%83%a5%e3%83%9c%e3%83%bc%e3%83%89/
-
checkout page saying site can’t be reachedhttps://wordpress.org/support/topic/checkout-page-saying-site-cant-be-reached/
-
Warning: An unexpected error occurredhttps://wordpress.org/support/topic/warning-an-unexpected-error-occurred-4/
-
Unable to Checkout the producthttps://wordpress.org/support/topic/unable-to-checkout-the-product/
-
Too much trafic breaking my sitehttps://wordpress.org/support/topic/too-much-trafic-breaking-my-site/
-
Ups! Page not foundhttps://wordpress.org/support/topic/ups-page-not-found/
-
Why WordPress Stuck in maintance mode?https://wordpress.org/support/topic/why-wordpress-stuck-in-maintance-mode/
-
There has been a critical error on this website.https://wordpress.org/support/topic/there-has-been-a-critical-error-on-this-website-259/
-
How to fix an account that is suspendedhttps://wordpress.org/support/topic/how-to-fix-an-account-that-is-suspended/
-
Solution on this message : Error establishing a database connectionhttps://wordpress.org/support/topic/solution-on-this-message-error-establishing-a-database-connection/
-
Fatal Errorhttps://wordpress.org/support/topic/fatal-error-3625/
-
technical issuehttps://wordpress.org/support/topic/technical-issue-3/
-
Wrong path to Log inhttps://wordpress.org/support/topic/wrong-path-to-log-in/
-
ucaught type errorhttps://wordpress.org/support/topic/ucaught-type-error/
-
Error 0x80070002 please helphttps://wordpress.org/support/topic/error-0x80070002-please-help/
-
Ошибка установки соединения с базой данныхhttps://wordpress.org/support/topic/%d0%be%d1%88%d0%b8%d0%b1%d0%ba%d0%b0-%d1%83%d1%81%d1%82%d0%b0%d0%bd%d0%be%d0%b2%d0%ba%d0%b8-%d1%81%d0%be%d0%b5%d0%b4%d0%b8%d0%bd%d0%b5%d0%bd%d0%b8%d1%8f-%d1%81-%d0%b1%d0%b0%d0%b7%d0%be%d0%b9-%d0%b4-2/