Web

Error Establishing a Database Connection in WordPress: Causes and Fixes

Talha Aslan 15 min read 1 views

What does the error establishing a database connection message mean and what do you do first?

The error establishing a database connection message means WordPress cannot reach the MySQL database that stores your site content. WordPress reads every page from that database, so the whole site fails when the link breaks. Wrong wp-config.php details, an unresponsive database server or damaged tables usually cause it.

Stay calm when you see it, and follow this order:

  1. Reload the page after a minute, because short server spikes can show the same message.
  2. Log in to your hosting panel and check whether the database tool opens.
  3. Compare the database name, user, password and host in wp-config.php with the panel.
  4. If the details match, ask your host whether the database server is running.
  5. Before you change anything, download a copy of your files and database.

This guide explains each step by cause. So instead of guessing, you start at the right place. Also, we never ask you to share real passwords or usernames anywhere.

When does this error message show up?

WordPress talks to the database on every page request. Posts, pages, settings and users all live there. When the connection fails, WordPress prints a short error and stops loading the page. Also, the text may differ slightly by language, and the German interface has its own official translation.

The error most often appears in these moments, so compare your case:

  • Right after you move to a new host or domain.
  • After you change the database password in the panel.
  • Whenever traffic jumps and a resource limit fills up.
  • If your host runs maintenance or restarts the server.
  • After tables break during a plugin or update process.

So the timing of the error establishing a database connection gives you a strong clue. If it started right after a change, look for a mismatch in the details. In practice, if it started on its own, look at the server or the resource limits. In short, this simple split turns a long guessing session into a short check.

Is it really an error establishing a database connection?

Not every blank screen is a database error. First, make sure you diagnose the right problem. Several WordPress issues look similar, and each one has a different fix.

For example, the "There has been a critical error on this website" message comes from plugin or theme code that crashed. So we cover that case in our critical error fix guide. A fully white screen may come from a PHP error or low memory. Then a general server failure is better handled with our 500 internal server error guide.

Here is what sets the error establishing a database connection apart: the message talks about the database connection, and no part of the site loads. Also, some installs show slightly different wording. In that case, treat it as a similar warning and follow the same order of checks.

Two quick questions speed up the diagnosis. Does the login page load? Does the error appear on every page? If the front end and the dashboard both fail, a connection problem is a strong candidate.

How do you fix the error establishing a database connection in wp-config.php?

The official WordPress documentation names wrong wp-config.php details as the most common cause. You reach the file through an FTP client or the file manager in your hosting panel. In practice, the file sits in the root folder of your WordPress install.

Compare four values with the panel:

  • Name: It must match the panel exactly, because some hosts add an account prefix.
  • User: This value can carry a prefix too, and it may be case sensitive.
  • Password: There must be no stray space at the start or the end.
  • Host: Many hosts accept localhost, but some give you a different address.

Also, open the file in a code editor, not in a word processor. Word processors turn straight quotes into curly ones and break the file. Next, save a copy of the file on your computer before you edit. Then you can restore the old version quickly if a change goes wrong.

Keep the structure intact while you edit. Also, each value sits between quotation marks. Change only the value inside them, and upload the file over the old one.

What do you do when the password does not match?

A password mismatch is a very common cause. If you reset the password in the panel and forget the file, the error starts at once. Likewise, restoring an old backup brings the old password back into the file. In other words, a backup can roll the password back too.

The safest method looks like this:

  1. Assign a new password to the database user in your hosting panel.
  2. Save the password in a password manager.
  3. Copy the same value into the password field in wp-config.php.
  4. Save the file and reload the site.

The WordPress documentation also suggests resetting the MySQL password manually if your configuration looks right. For complex passwords, paste the value instead of typing it. Never share real passwords in chats or emails, and use the secure channel in your panel instead.

If another app uses the same database user, update it too. For example, a second site or a scheduled backup job keeps the old password and fails. In short, this way you do not fix one problem and create another.

Why can the database host value be wrong?

The host field tells WordPress which server holds the database. On many shared plans this value is localhost, because the database sits on the same machine as the web server. However, some providers run the database on a separate machine and give you a custom address.

The host value can stay wrong in these cases:

  • You moved to a new host and the old address stayed in the file.
  • Your provider moved the database server to another machine.
  • The setup needs a port number and you did not add it.

Specifically, find the right value on the database info screen in your panel or in your provider's help pages. Do not guess. However, a wrong host usually gives the same generic message, so confirming the value at the source saves time.

What happens when the database user lacks privileges?

Even with correct details, the server refuses the link if the user is not tied to the database. Creating a database and creating a user are separate steps in most panels. If you forget to assign the user to the database and grant the needed privileges, you get the same error.

This is common on fresh installs and migrations. For example, you create a new database and import the content, but you never add the user. WordPress sends the right password, and the server still denies access.

Instead, check this in your panel: does the user appear on the right database, and are the privileges set? For a step by step walkthrough, see our guide to creating a MySQL database in cPanel with users and privileges. We cover the creation process there, so we do not repeat it here.

Some panels list privileges one by one. WordPress needs to create, read and change tables in its own database. A missing privilege can leave part of the site working and part broken. Since the exact list varies by provider, look for an option that grants all privileges on that one database.

How can you tell that the database server is not responding?

If your details are correct, the problem may sit on the server side. Meanwhile, the database server may have crashed, entered maintenance or run out of capacity. In addition, the WordPress documentation lists a server that is down among the host-side causes.

These signs point to a server problem:

  • The database tool in your hosting panel loads very slowly or not at all.
  • Other sites on the same server show the same error.
  • The error comes and goes, and sometimes a reload fixes it.
  • Your host's status page or announcements mention maintenance.

Then, if you see these signs, do not touch wp-config.php. Changing correct details only makes things worse. Instead, write to your provider with the time of the error and the affected domains. Also note how long the problem lasts, so the support team gets concrete facts.

Ask a specific question: was there an outage or maintenance on the database server at these times? A concrete question gets a faster answer than a general complaint. Meanwhile, consider a simple maintenance page, so visitors see a clear note instead of a raw error.

How do resource limits and quotas trigger this error?

Shared hosting plans cap database connections, memory and processing time. When your site passes a cap, the provider can refuse connections for a while. WordPress then cannot reach the database and shows the same message.

The WordPress documentation also notes that a database can hit its quota and shut down. Once the quota fills, writes stop, and sometimes the database stops answering at all.

Typical reasons for hitting a limit include:

  • A sudden traffic spike or heavy bot crawling.
  • A slow plugin with inefficient queries.
  • Bloated temporary data and old revision records.
  • A hosting plan that is too small for the site.

To learn how these caps work, read our guide to shared hosting resource limits for CPU, RAM and I/O. For the speed side of the story, see how site speed affects SEO.

A bigger plan is not the only fix. First find where the load comes from. Removing unused plugins, adding caching and shrinking images often costs less than an upgrade. Still, if traffic truly grew, a stronger plan makes sense. Check current quotas and limits on your provider's own pages.

How do you use the WP_ALLOW_REPAIR constant for broken tables?

Sometimes the connection works, but the tables suffer damage. Also, a power cut, a server crash or an interrupted update can cause it. WordPress ships a built-in repair tool for this case.

According to the official documentation, you enable it by adding a line to wp-config.php that defines the WP_ALLOW_REPAIR constant as true. Then you open the wp-admin/maint/repair.php path on your site. Then the page offers a repair option and a repair and optimize option.

Above all, keep three points in mind:

  1. Take a backup first, because repair changes the tables.
  2. The documentation says users do not need to log in while the feature is on, so anyone can reach the page.
  3. Remove the line as soon as the repair finishes.

If you forget the line, strangers can open the repair page. So keep the session short and confirm at the end that the page no longer works. We do not paste a code block here, because the exact line sits in the official documentation.

When the repair ends, WordPress lists which tables it checked and fixed. In practice, if the error remains, the cause lies elsewhere. In addition, the repair tool fixes tables only and does not solve wrong connection details. So if the details are wrong, the repair page will not open either, and you must fix the connection first.

Why does the error establishing a database connection follow a migration?

Moving a site to a new host, a new domain or from a local setup to a live server often triggers this error. Put simply, database names, users and hosts differ on every environment. So if you copy the files and leave the old values in wp-config.php, the connection fails.

After a migration, run through this list:

  • Did you create the database on the new host?
  • Was the backup imported into the right database? Check that too.
  • Have you attached the user to the database with privileges?
  • Are all four values in wp-config.php updated?
  • Did the import finish without errors or interruptions?

Our database backup and restore guide covers the backup side. To plan the whole move, use the hosting change checklist. Then that way you verify everything before you delete the old server.

Do not confuse a domain move with a hosting move. Pointing a domain elsewhere does not change database details. What changes is the server that holds your files. So after a migration error, enter the values from the new server, because the old ones may no longer work.

What does it mean if the dashboard shows a different message?

Sometimes the front end loads but the dashboard shows another message. That tells you WordPress can reach the database and hit a different problem. So you should not apply the same fix as for a failed connection.

Here is how we sort the cases you may meet:

  • A similar warning that says tables are missing or need repair. In this case, try the repair tool.
  • A prompt that asks you to update the database. This is a separate update flow.
  • Only the dashboard fails while the front end works. This usually points to a plugin or theme conflict.

The exact text of the error establishing a database connection can change with the version and the language. So do not fixate on the wording. Ask whether the message is about the connection, the tables or an update, and act on that cause.

Can a hacked site also cause a database connection error?

Yes, it can. In addition, the WordPress documentation lists a compromised website among the possible causes. An attacker may have changed the database details, deleted tables or damaged files.

These signs point to a security problem:

  • You changed nothing, yet the details suddenly broke.
  • Your files contain new items you do not recognize or have odd dates.
  • Search results show content on your site that you did not publish.
  • Your host sent a malware warning.

In that case, change your passwords and check your backup. For detailed steps, read our hacked WordPress site guide. Also, never give admin access to strangers who offer paid site rescue. That creates a second security problem.

Put the steps in the right order. Change your admin and hosting passwords first. Then compare file changes against your provider's records. A clean backup is often the safest path. Do not try shortcuts that bypass your systems, because they put your account and customers at risk.

Which symptom points to which cause?

The table below pairs each symptom with a likely cause. It shows where to look first and does not replace a real diagnosis.

SymptomLikely causeFirst check
Started after a migrationOld details left in the fileThe four values in wp-config.php
Started after a password changePassword mismatchPassword in panel and file
You just created a new databaseUser privileges missingUser and database link
Comes and goesResource limit or server loadHosting resource usage
Every site failed at onceDatabase server problemProvider status and support
Dashboard warns about tablesDamaged tablesRepair tool and backup
Files changed unexpectedlySecurity breachPasswords and cleanup guide

The order in the table is not strict. Several causes can exist at once, so finish each check in turn.

What is the full checklist for the error establishing a database connection?

The list below gathers the whole article in one place. Follow the steps without skipping any.

  1. Reload the page and try another browser.
  2. Check whether the hosting panel and the database tool open.
  3. Look at the other sites on the same account.
  4. Download a backup.
  5. Compare the name, user, password and host in wp-config.php with the panel.
  6. Confirm that the user belongs to the right database with privileges.
  7. Check resource usage and quota status.
  8. If needed, switch on the repair tool, use it and switch it off.
  9. Rename the plugins folder for a moment to test for a plugin cause.
  10. If nothing helps, contact your provider with all the facts.

Keep this list at hand when the error establishing a database connection strikes. In most cases, you find the cause within the first five steps.

How do you prevent the error from coming back?

After you fix the problem, build a few habits. Most database errors come from avoidable changes.

  • Back up often. Keep both files and database. Our website backup strategy guide offers a routine.
  • When you change a password, update both places: the panel and wp-config.php.
  • Keep plugins and themes current, but take a backup before each update.
  • Delete plugins you do not use, so the database carries less load.
  • Watch your resource usage and review the plan when you near a limit.
  • Follow a checklist whenever you migrate.

Also switch off the repair constant and any debug constants as soon as you finish. Every diagnostic feature left on is a small security risk. A maintenance routine protects you on your busiest sales day too.

Test your backups once a month. A backup file is one thing, and a backup that restores is another. Follow your provider's maintenance notices and avoid big changes right before major campaigns.

When should you ask your host or an expert for help?

If you finished the checklist and the error stays, it is time to ask for help. Only your provider can see the database server, so write to them first.

Include these facts in your request:

  • The date and time the error began.
  • The last change you made before it started.
  • Whether the database tool in your panel opens.
  • The state of other sites on the same account.
  • That you already compared the wp-config.php details with the panel.

This helps the support team narrow the problem faster. If the problem lies in code, hire an experienced WordPress developer. Do not trust anyone who guarantees results, asks for payment upfront or wants your login details by message. No recovery method guarantees an outcome.

How can Talha Aslan and team help?

We are a digital marketing team based in Istanbul, and we are not a hosting company. We do not run servers. Still, we can review your site structure, your WordPress setup and likely weak points with you.

When you build or rebuild a site, our web design service plans maintenance, backups and migration from day one. So we aim to cut down this kind of outage early. You can also try our free tools to measure page performance.

This article is general information. Server settings differ by provider, so menu names and steps may look different. For current details, check the official WordPress sources: common WordPress errors, the wp-config.php documentation and the WordPress support forums.

Frequently Asked Questions

Does the error establishing a database connection message delete my data?
No, the message alone does not delete anything. It only tells you that WordPress cannot reach the database. Your posts and settings usually stay where they are. Still, download a backup from your hosting panel before you repair tables or move files, so you always keep a way back.
What should I check first when the error appears suddenly?
Check whether the database server responds at all. Open your hosting panel and see if the database tool loads. If it does, compare the details in wp-config.php with the panel. If the panel fails too, the problem likely sits on the server side, so contact your host.
I changed the database password and the error started. What now?
Copy the new password into the matching field in wp-config.php exactly. An extra space, a missing character or a curly quote breaks the connection. Once the panel and the file hold the same value, the connection usually returns. Paste the value instead of typing it, then reload the site.
Can I leave the WP_ALLOW_REPAIR constant switched on?
No, you should not. The WordPress documentation says to enable it only when you need it and to remove it once the problem is solved. While it is on, the repair page does not require a login. Delete the line right after the repair and confirm that the page no longer opens.
Should I go back to the old server after a migration error?
Usually not. Most post-migration errors come from old database names, users or hosts that stayed in the configuration file. Update them with the values from the new hosting panel. Keep the old server untouched until you confirm that the new site works well, so you can roll back if needed.
Who should I contact if I cannot fix it myself?
Start with your hosting provider, because only they can see the database server. After that, work with an experienced WordPress developer if the problem lies in code or configuration. Never hand your admin details to strangers who promise paid site rescue, and remember that no method guarantees a result.
  • wordpress errors
  • database connection error
  • wp-config.php
  • mysql
  • wordpress repair
  • site migration
  • hosting problems
Share:
Talha Aslan

Google Partner digital marketing expert. Hands-on with SEO, Google Ads, web design and e-commerce projects since 2012; every post here comes from that experience.

Next project

Let's talk about your project.

Your brief goes straight to Talha Aslan and team: strategy led by Talha, delivery by an experienced team. The first consultation is free; we listen and come back with a clear roadmap.