Home โ†’ Blog โ†’ Database Error Fix
WordPress

WordPress "Error Establishing a Database Connection" โ€” How to Fix It

By Global Website Designerยท8 min readยทJune 2025

"Error establishing a database connection" is one of the most alarming WordPress errors โ€” it takes down both your site and your admin dashboard. The good news: there are only 5 real causes and each has a clear fix.

๐Ÿ”ด This error means your site is completely down for all visitors. Act quickly. If you need emergency help, WhatsApp us now.

What Causes This Error?

  • Wrong database credentials in wp-config.php
  • MySQL server is down or crashed
  • Database is corrupted
  • Database user doesn't have the right permissions
  • Too many database connections (server overloaded)

Step 1: Check Your wp-config.php Credentials

This is the most common cause. Log in to your hosting cPanel or Hostinger file manager and open wp-config.php in the root of your WordPress installation. You'll see these lines:

define( 'DB_NAME', 'your_database_name' ); define( 'DB_USER', 'your_database_user' ); define( 'DB_PASSWORD', 'your_password' ); define( 'DB_HOST', 'localhost' );

Now go to your hosting control panel โ†’ MySQL Databases. Check that:

  • The database name in wp-config matches an actual database
  • The username exists and is assigned to that database
  • The password is correct (reset it if unsure, then update wp-config.php)
  • DB_HOST is correct โ€” usually 'localhost' but some hosts use a different value

Step 2: Test the Database Connection Directly

Create a test file to verify the credentials work. Via file manager, create a file called testdb.php in your WordPress root:

<?php $link = mysqli_connect('localhost', 'DB_USER', 'DB_PASSWORD', 'DB_NAME'); if (!$link) { die('Connection failed: ' . mysqli_connect_error()); } echo 'Connected successfully'; mysqli_close($link); ?>

Replace the values with your actual credentials from wp-config.php. Visit yourdomain.com/testdb.php. If it says "Connected successfully", the credentials are fine and the issue is elsewhere. Delete this file immediately after testing.

Step 3: Check if MySQL is Running

Sometimes the MySQL server itself crashes, especially on low-resource shared hosting. Log in to your Hostinger or cPanel panel and look for a MySQL server status. You can also contact your host's support and ask "Is the MySQL server running for my account?" โ€” they can restart it.

Step 4: Repair a Corrupted Database

If the credentials are correct but you still get the error, the database may be corrupted. WordPress has a built-in repair tool. Add this line to wp-config.php:

define('WP_ALLOW_REPAIR', true);

Then visit: yourdomain.com/wp-admin/maint/repair.php

Click "Repair Database". Once done, remove the WP_ALLOW_REPAIR line from wp-config.php immediately.

Step 5: Repair via phpMyAdmin

If the above doesn't work, use phpMyAdmin (available in cPanel/Hostinger panel):

  1. Open phpMyAdmin and select your WordPress database
  2. Select all tables (check the box at the bottom)
  3. From the "With selected" dropdown, choose "Repair table"
  4. Wait for all tables to complete

Step 6: Check Max Connections

If your site is on shared hosting and gets sudden traffic spikes, you may hit the database connection limit. Signs: the error appears intermittently, not constantly. Solutions: upgrade to a VPS plan, or add persistent database connections. Contact your host to check max_connections.

Database Error Still Not Fixed?

We fix WordPress database errors same day โ€” without data loss. WhatsApp us for emergency help.

Get Emergency Database Fix โ†’
GW
Global Website DesignerWordPress Emergency Specialists

Site down? WhatsApp us for same-day database repair.