rawatweb

Error Establishing a Database Connection in WordPress

Error establishing a database connection wordpress: seeing Error Establishing a Database Connection? Check credentials, the MySQL server, quotas.

An editorial link between WordPress and a database server that is cut in the middle.

Your site suddenly shows a single line of text: “Error establishing a database connection”. No menu, no articles, no admin. Every other page is the same. To a site owner it looks like total disaster.

The message is actually quite specific. WordPress is already running, has loaded wp-config.php, and then failed to open a connection to the database server. That means the problem sits in one of three places: the credentials, the database service, or permission to reach it.

Short answer: first check whether the host name, database name, user, and password in wp-config.php still match the hosting panel. If they do, ask the host whether MySQL is running and whether your account has hit a connection limit or quota. Only then check whether wp-config.php is damaged or truncated. Do not touch the contents of the database before the cause is clear.

What is actually failing

WordPress keeps almost everything—posts, pages, settings, users, comments—in a MySQL or MariaDB database. When a page is requested, PHP opens a connection using the details in wp-config.php:

define('DB_NAME', 'database_name');
define('DB_USER', 'database_user');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');

If any value does not match, or the server does not answer, WordPress stops right there. No page is rendered, so all you see is that one line. It is worth being explicit: this message is not a sign the database was deleted. When a database is missing, the message usually differs—“unknown database”, or a table-not-found error.

Four causes that cover most cases

Nearly every occurrence falls into one of these groups:

1. Changed credentials. The database user’s password was changed in the hosting panel but wp-config.php was not updated. Or the reverse: the site files were restored from an older backup carrying the old password.

2. The database server is not running. Host maintenance, a MySQL process killed by memory pressure, or a database node being migrated. This is most common on shared hosting.

3. Connection limits or quotas. Some plans cap concurrent connections. If the site takes a traffic spike, or a plugin opens excessive connections, new ones are refused. A full disk quota can also stop MySQL from writing and lead it to refuse connections.

4. A damaged config file. wp-config.php truncated during upload, odd characters inserted, or a line deleted during an edit. This frequently follows a migration or a quick edit through a file manager.

Error establishing a database connection wordpress: The raw messages behind the generic one

The page you see is almost always the generic version. The actual cause is written in wp-content/debug.log or on screen once WP_DEBUG is on. Six messages cover nearly every case, and each one points somewhere different:

MessageMeaningFirst fixTime to resolve
Error establishing a database connection with no detaildetails suppressed by display_errors = Offenable the log, read debug.log5 minutes
(HY000/1045): Access denied for user 'dbuser'@'localhost' (using password: YES)credentials rejectedmatch them against the hosting panel10 minutes
(HY000/2002): Can't connect to local MySQL server through socketMySQL not running, or a different socketcheck phpMyAdmin, contact hosting15 minutes–2 hours
(HY000/1049): Unknown database 'name'wrong database name, or it was droppedcreate it again or fix DB_NAME10 minutes
(HY000/1040): Too many connectionsconnection limit reachedcut load or raise the plan30 minutes
MySQL server has gone awaytimeout or server restartraise wait_timeout, split large queries20 minutes

1045 and 1049 you can fix yourself. 2002 almost always ends at the hosting desk.

Error establishing a database connection wordpress: Limits worth comparing before you escalate

wp db query "SHOW VARIABLES LIKE 'max_connections';"
wp db query "SHOW VARIABLES LIKE 'wait_timeout';"
wp db query "SHOW STATUS LIKE 'Threads_connected';"
wp db query "SHOW STATUS LIKE 'Max_used_connections';"

MySQL 8 defaults to max_connections 151 and wait_timeout 28800 seconds (8 hours). Shared hosting usually cuts the connection cap far below that — 10 to 25 is normal — so a Threads_connected figure near the limit rejects the next visitor even when the server itself is healthy. On the PHP side, max_execution_time 30 seconds and memory_limit 256 MB are the usual defaults, and if the site runs PHP-FPM the pm.max_children pool size decides how many requests can run at once.

A safe check order

Start with steps that change nothing:

  1. Check the hosting panel for maintenance notices or database service errors.
  2. Open another page and /wp-admin. If everything shows the same message, it is a global connection problem, not one broken page.
  3. Compare the database details in the hosting panel with wp-config.php. Pay particular attention to DB_HOST—some hosts use a special hostname, not localhost.
  4. Try logging into phpMyAdmin with the same user. If phpMyAdmin works, the database server is alive and the problem is credentials or permissions.
  5. Check disk space and quotas in the hosting panel.
  6. Ask the host whether a connection limit was reached or the account was temporarily blocked.

Step 4 is the most useful discriminator. If phpMyAdmin succeeds, you can narrow the problem to the configuration file. If phpMyAdmin also fails, the server is at fault and only the host can fix it.

wp-config credentials wrong: the first check

If you find the database password has changed, fix wp-config.php, not the database. The order:

  1. Create a new database user or reset the existing user’s password in the hosting panel.
  2. Grant access only to that site’s database—not to every database in the account.
  3. Update DB_USER and DB_PASSWORD in wp-config.php.
  4. Save, then reload the site.

A few notes: make these changes over a secure connection, never paste the password into tickets or chat, and avoid over-broad privileges. On accounts hosting more than one application, separate database users prevent one application from reaching another’s data.

If you use a configuration manager or automated deployment, remember that wp-config.php can be overwritten on the next deploy. Update the source as well, not just the file on the server.

MySQL connection refused wordpress: the server side

When phpMyAdmin will not open either, there is little you can do alone. What to tell the host:

  • The exact error message, including when it first appeared.
  • Whether phpMyAdmin is reachable.
  • Whether any plan change, server move, or maintenance is in progress.
  • Whether there was a traffic spike or a process consuming resources.

While you wait, avoid making things worse: do not re-import the database, do not change wp-config.php repeatedly, and do not install new plugins “to try”. Every change while the server is unstable makes diagnosis harder.

If the site takes orders, prepare a temporary static page outside WordPress so customers still get information. For broader scenarios—including when a site must be recovered quickly—see the website emergency service.

When the config file is damaged

A damaged config file looks similar: the connection fails, but the credentials in the hosting panel are correct. How to check:

  • Compare the size and line count of wp-config.php with a backup copy.
  • Look for odd characters at the start or end of the file, often added by an editor that writes a BOM.
  • Ensure no line is cut in the middle, especially around the DB_ definitions and $table_prefix.
  • Confirm the file ends with require_once ABSPATH . 'wp-settings.php';.

The safest fix: take wp-config.php from the most recent backup you know is correct, replace the four DB_ values to match the hosting panel, then upload it again. Do not copy wp-config.php from another site—the security keys (AUTH_KEY and friends) differ and every user session becomes invalid.

After the site is back

Once the site loads, check a few things immediately, because this message is often an early symptom:

  • Error log entries, to see whether some process keeps failing—a plugin retrying connections, for example.
  • Table count in the database. Missing tables can leave a site that loads but has lost specific data.
  • Disk space, because a full disk usually recurs within days.
  • Traffic load, whether a spike exceeded the connection limit.
  • The latest backup, and confirm it includes the database rather than only files.

One check that is often skipped: run wp db check if WP-CLI is available, or inspect tables through phpMyAdmin. A damaged table can make a site behave unpredictably even when the connection succeeds.

A short checklist for the host ticket

If you end up contacting the host, the speed of resolution depends heavily on what you include. Put it in one message: the domain, the exact error, when it first appeared, whether phpMyAdmin opens, whether a plan change or migration happened, and whether other sites on the same account fail the same way. That last detail is often skipped and is the most useful—if two sites on one account fail together, the cause is almost certainly server-level rather than your site.

Also list what you already tried, such as matching credentials or replacing the config file. That prevents being asked to repeat steps and gets the ticket escalated to the right technical team faster.

When the problem will come back

If the cause is a quota or connection limit, a similar failure returns at the next spike. The signs: the message appears during busy hours, disappears on its own after a few minutes, then returns. When the pattern looks like that, the answer is not patching code but adjusting the hosting plan or reducing load. Error establishing a database connection wordpress comes back when a password change was applied in one place only.

Common sources of load:

  • A plugin running heavy queries on every page.
  • No object cache, so every request hits the database.
  • Internal search scanning entire tables.
  • Bots or scrapers flooding dynamic pages.
  • Scheduled tasks all firing during peak hours.

Adding an object cache such as Redis usually delivers the largest improvement for a reasonable cost, provided the host supports it. For small sites, removing heavy plugins is sometimes enough.

Realistic prevention

Not every database incident is preventable—host maintenance is outside your control. But the impact can be reduced:

  1. Daily database backups stored off the server, restored occasionally as a test.
  2. Uptime monitoring that checks a dynamic page, not only a static homepage.
  3. Database credentials recorded in a password manager, so nothing is guessed during an emergency.
  4. No direct edits to wp-config.php on production without a saved copy.
  5. The host’s support contact and hours known before you need them.
  6. A separate database user per application on shared accounts.

A tested backup is what separates a one-hour outage from permanent data loss. The full guide is in backups you can actually restore, with the routine care context in WordPress website care.

Error establishing a database connection wordpress: what matters first

This message means WordPress cannot open a connection to MySQL or MariaDB—not that your data is gone. The site stops before it can render anything. Separate four causes: wrong credentials in wp-config, a database server that is down, exhausted quotas or connection limits, and a damaged config file.

Frequently asked questions

Is my data gone? Almost certainly not. This message appears because a connection did not open, not because the database contents were deleted. The real danger is panicked action such as importing an old dump or dropping the database.

Why does localhost not work? Some hosts use a special internal hostname, an IP address, or a specific port for the database. The correct value is always in the hosting panel, not in a generic tutorial.

Can I fix this without hosting access? If the cause is credentials in wp-config.php, yes—as long as you have file access. If the database server is down, only the host can start it.

Would switching theme or plugin fix it? Very rarely, and it usually adds variables. Focus on the connection first; themes and plugins are irrelevant until the site can open the database.

If you are unsure where to start, begin with a free audit or contact us through the contact page with the exact error message, when it started, and whether phpMyAdmin is reachable. Those two details usually point the way.

Read next: WordPress Layout Breaks After Enabling Caching, WordPress 404 After Changing Permalinks: How to Fix It, WordPress Emails Not Being Delivered: What to Fix.

#wordpress database connection #mysql error #wp-config #database down
Let's talk about your website

Does any of this look like your website?

Tell us on WhatsApp. We look first, explain what needs fixing, then you decide. For a fuller picture, request the free audit.

Chat with us