What Does This Error Mean?
If you open your site and see only the message "Error establishing a database connection" instead of your content, it means your WordPress files are working but they can't reach the MySQL database where your data is stored. Because all of WordPress's content (posts, pages, settings, users) lives in the database, the site becomes completely inaccessible when that connection drops.
This is one of the most common errors WordPress users run into and one of the most searched on Google. The good news: the cause is usually clear, and in most cases it's fixed within a few minutes.
The Most Common Causes
This error usually comes down to one of the following: incorrect database credentials in the wp-config.php file (the most frequent cause), the database server not responding (a hosting issue), corrupted database tables, or a temporary block from the host due to traffic or limit overages.
Solution 1: Check Your wp-config.php Credentials
This is the most common fix and the first place you should look. Using cPanel File Manager or FTP, open the wp-config.php file in your site's root directory and find these four lines:
define('DB_NAME', 'veritabani_adi');
define('DB_USER', 'kullanici_adi');
define('DB_PASSWORD', 'parola');
define('DB_HOST', 'localhost');
Make sure these details exactly match the real database name, username and password in your hosting panel (cPanel > MySQL Databases). Especially if you've just migrated the site, these values most likely belong to the old server and need to be updated.
DB_HOST tip: On most hosts, localhost is correct. However, some providers use a different host name (for example mysql.yoursite.com or an IP). You can find the correct value in your hosting provider's panel or from their support team.
Solution 2: Check the Database User's Privileges
Even if the credentials look correct, the database user may not have permission to access that database. In cPanel, go to the MySQL Databases section, and confirm that the relevant user is attached to the database and has been granted "All Privileges". If privileges are missing, re-add the user with all privileges.
Solution 3: Repair the Database
If the error message appears differently in the dashboard (wp-admin) than on the front end, or if you see a "database needs to be repaired" warning, your tables may be corrupted. To enable WordPress's built-in repair tool, add the following line to the end of the wp-config.php file, just above the /* That's all, stop editing! */ line:
define('WP_ALLOW_REPAIR', true);
Then go to https://www.yoursite.com/wp-admin/maint/repair.php in your browser and start the repair. Once the repair is finished, be sure to delete the line you added for security reasons; otherwise this page stays publicly accessible.
Solution 4: Check the Hosting Server
If the wp-config.php details are definitely correct, the problem may be on the hosting side. The database server could have crashed, be under maintenance, or your connection limit on a shared plan may have been reached. In that case, check the status of your other sites and contact your hosting provider to ask whether the database server is running. Limit overages are common on high-traffic sites and usually require a plan upgrade.
Solution 5: Test the Database Connection
To find out whether the issue really is the connection, you can create a simple test file (testdb.php) in the root directory with a connection attempt inside it, or check from phpMyAdmin whether you can log into the database. If you can log into phpMyAdmin and see your tables, the database is up and the problem most likely lies in the wp-config.php credentials.
Steps to Prevent This Error
The best way to never run into this error is to take preventive measures. First and foremost, take regular backups; install an automated backup plugin (for example UpdraftPlus) that covers both your files and your database. That way you can roll back within seconds if something gets corrupted. Second, know the traffic and database limits of your hosting plan; as your site grows, a shared plan may become insufficient, and limit overages lead to this error. Third, instead of applying plugin and theme updates directly on the live site, first try them in a staging environment; a failed update can corrupt your database tables.
Why Backing Up wp-config.php Matters
wp-config.php is WordPress's most critical file; it contains your database connection details and your security keys. Before making any edit to this file, always make a copy of it. A single wrong character, a missing quotation mark or a deleted semicolon can take your entire site down. When editing, open the file in a code editor (for example Notepad++ or VS Code); programs like Word can corrupt quotation marks and cause errors that are hard to spot. If the site won't load after a change, you can restore the backup you took and return to the previous working state within seconds.
Frequently Asked Questions (FAQ)
Will I lose my site's data while fixing this error?
No. This error usually stems only from the database being unreachable; your data stays in the database. Once you correct the wp-config.php details and the connection is re-established, your content comes back exactly as it was. Even so, it's safest to back up the file and the database before any intervention.
Where do I find the wp-config.php file?
The wp-config.php file is located in the root directory of your WordPress installation (usually inside the public_html folder). You can access this file with cPanel File Manager or an FTP program such as FileZilla.
What should I put for DB_HOST?
On most hosts the DB_HOST value is localhost. However, some providers use a different host name (for example mysql.yoursite.com) or an IP address. You can find the correct value in your hosting provider's panel or from their support team.
Conclusion
As scary as the "Error establishing a database connection" message looks, the fix is usually simple. First, compare the database details in the wp-config.php file with the real values in your hosting panel; most problems are resolved right there. If the details are correct, check user privileges, database repair, and finally the hosting side. By taking regular backups, you can return within seconds without fearing issues like this.