If your website shows the message "Error establishing a database connection", WordPress is running but cannot talk to the database where your content is stored.
Every page, post, product, order, user and setting on a WordPress website lives in that database. When WordPress cannot reach it, there is nothing to display, so the whole site usually stops at that single line of text. The dashboard is normally affected too.
The message looks serious, and for a business website it is: visitors see nothing useful until it is fixed. However, in most cases it does not mean that your data has been deleted. It usually means that the database is temporarily unreachable, overloaded, or that WordPress is using the wrong details to connect to it.
This guide explains what the message means, the most common causes, what you can check safely and when it is better to ask for technical support.
What does this error actually mean?
A WordPress website has two main parts:
- the files, such as WordPress itself, plugins, themes and uploaded images
- the database, which stores the content and settings
When someone opens a page, WordPress reads a configuration file called wp-config.php to find out where the database is and how to log in to it. It then connects to the database server and asks for the content of the page.
The error appears when that connection fails. WordPress does not know exactly why, so it shows the same generic message whether the database server is down, the password is wrong or the server is simply too busy to answer.
That is why the message alone cannot tell you what caused the problem. It tells you where the problem is, not what it is.
Is my content lost?
Usually not.
In most cases the data is still there. WordPress just cannot reach it at the moment. Once the connection is restored, the website normally reappears exactly as it was.
There are exceptions, for example a failed server, a deleted database or serious corruption. These are less common, and they are another reason to avoid hasty actions such as restoring an old backup or reinstalling WordPress before the cause is known.
What are the most common causes?
The database server is down or overloaded
On most hosting plans, the database runs on a server managed by the hosting provider. If that server is restarting, under maintenance or overloaded, WordPress cannot connect.
Signs that point in this direction:
- the error appeared suddenly, without anyone changing the website
- it comes and goes, especially at busy times
- other websites on the same hosting account show the same error
- the hosting provider reports an incident or maintenance
A traffic spike, an aggressive bot, a heavy import or a badly behaving plugin can also overload the database, so that some requests fail while others succeed.
The connection details in wp-config.php are wrong
wp-config.php contains four details WordPress needs to connect:
- the database name
- the database user
- the password of that user
- the database host, meaning the address of the database server
If any of these is wrong, the connection fails. This often happens:
- after a migration to a new hosting provider or server
- after the database password was changed in the hosting panel
- after someone restored an old copy of
wp-config.php - after the hosting provider moved the database to a different server
- after the database user was deleted or lost its permissions
If the error appeared right after one of these events, this is the most likely cause.
The database tables are damaged
Database tables can become corrupted, for example after a server crash, a full disk or an interrupted operation. In that case WordPress may connect but fail to read what it needs.
Sometimes the public site shows the connection error while the dashboard shows a different message suggesting that the database needs to be repaired.
The hosting account has reached a limit
Hosting plans often have limits on:
- the number of simultaneous database connections
- disk space, which the database also uses
- the size of the database
- CPU or memory usage
When a limit is reached, the database may refuse new connections or stop working properly. The hosting provider can usually confirm this quickly.
The account was suspended
If the hosting account was suspended, for example for an unpaid invoice, a policy issue or a security problem, the database may be disabled while the files remain online. Check for emails from your hosting provider.
What should you check first?
You do not need to open any files to collect useful information.
Check whether the error is constant or intermittent
Reload the website a few times over a few minutes, preferably in a private or incognito window.
- If the error is always there, a configuration problem or a database that is fully down is more likely.
- If it comes and goes, overload or hosting limits are more likely.
Check whether anything changed
Think about what happened just before the error appeared:
- Was the website migrated or moved to a new server?
- Did someone change a password in the hosting panel?
- Was a backup restored?
- Did the hosting provider announce maintenance?
- Was a large import, newsletter or promotion running?
- Did anyone install a new plugin?
A note such as "the error started the morning after we changed the database password" can save a lot of investigation time.
Check other websites on the same account
If you host several websites with the same provider, open them. If they all show the same error, the problem is very probably on the hosting side, not inside your WordPress installation.
Check your hosting provider's status and emails
Look for:
- a status page or incident notice from your hosting provider
- emails about maintenance, limits or suspension
- warnings about disk space in the hosting panel
What can you safely try?
Contact your hosting provider
For this particular error, the hosting provider is often the best first contact. They can usually confirm within a short time whether:
- the database server is running
- the database and its user still exist
- the account has reached a limit
- the database host value you should use is correct
- there was an incident or maintenance
Ask them clearly: "Is the database server for my account running, and are the database name, user and host still the same?"
Contact whoever last worked on the website
If a developer, agency or colleague recently migrated the site, changed hosting settings or restored a backup, ask them what they changed. They may know immediately which value needs to be corrected.
Wait a few minutes if the error is intermittent
If the hosting provider confirms a temporary overload or maintenance, the website may return on its own. That still leaves a question worth answering later: why the database was overloaded, and whether it could happen again during an important moment for your business.
What should you avoid doing?
When the website is down, it is tempting to try several fixes quickly. Avoid:
- reinstalling WordPress
- restoring a backup before you know the cause, because it may overwrite recent orders, form entries or content
- creating a new empty database and pointing WordPress to it, which makes the site look like a fresh installation
- deleting or recreating the database user without noting the old details
- editing
wp-config.phpwithout first saving a copy of the original - copying random code or settings found in forums
- running repair tools repeatedly without understanding what they do
If you see the WordPress installation screen instead of your website after a change, stop. It usually means WordPress is connected to an empty or different database, not that your content is gone. Do not complete the installation.
When should you ask for technical support?
Ask for help when:
- the error persists and the hosting provider says everything is fine on their side
- the error appeared after a migration or restore
- the site handles orders, bookings, subscriptions or customer data
- the error keeps coming back during busy periods
- the dashboard says the database needs to be repaired
- you are not comfortable editing
wp-config.php - you are not sure whether a recent backup is reliable
- you suspect the website may have been compromised
You do not need to identify the cause yourself first. A useful request can simply describe what you see, when it started and what changed.
What information should you collect?
Useful details include:
- the website URL
- a screenshot of the error
- when the problem started
- whether the error is constant or intermittent
- any recent change, such as a migration, password change or restore
- the name of the hosting provider
- any email or ticket reply from the hosting provider
- whether other websites on the same account are affected
- whether a recent backup is available
Do not send database passwords or hosting credentials by ordinary email. D4Hub can tell you which access is needed and how to share it safely.
How D4Hub can help
The goal is not only to make the error disappear, but to understand why the connection failed and reduce the chance of it happening again.
Depending on the situation, D4Hub can help with:
- checking the database connection details used by WordPress
- coordinating with your hosting provider to confirm the state of the database server
- correcting configuration problems after a migration or password change
- checking and repairing damaged database tables safely
- investigating overload, slow queries or plugins that put pressure on the database
- reviewing hosting limits and recommending a more suitable setup
- evaluating whether a backup restore is needed and what data it might overwrite
- testing login, forms, checkout and other key functions once the site is back
You can ask for support at any stage, whether you have just seen the error, have already spoken with your hosting provider or have tried a fix that did not work.
Open a support ticketFor hands-on users: checking the database connection
The following checks are for people comfortable with SFTP, SSH, WP-CLI and their hosting panel.
Before changing anything, download a copy of wp-config.php and, if possible, make a backup of the database. Never paste wp-config.php, passwords or full logs into public forums or support chats.
Check the database details in wp-config.php
Open wp-config.php, usually in the main WordPress folder, and find these lines:
define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_user' );
define( 'DB_PASSWORD', 'database_password' );
define( 'DB_HOST', 'localhost' );Compare each value with what your hosting panel shows for the database and its user. Pay attention to:
- prefixes that some hosts add automatically to database and user names
DB_HOST, which is not alwayslocalhost: some providers use a separate hostname, a port such aslocalhost:3306or a socket path- passwords containing a single quote or backslash, which must be escaped inside the PHP string
If you change a value, change one thing at a time and reload the website after each change.
With WP-CLI you can read the values without opening the file:
wp config get DB_NAME
wp config get DB_USER
wp config get DB_HOSTTest the connection with the mysql client
If you have SSH access, try connecting with the same details WordPress uses:
mysql -h localhost -u database_user -p database_nameReplace localhost, database_user and database_name with your own values. The -p option makes the client ask for the password instead of saving it in your shell history.
If the connection works, list the tables:
SHOW TABLES;Then type exit to leave.
How to read the result:
- "Access denied": the user, password or permissions are wrong
- "Unknown database": the database name is wrong or the database no longer exists
- "Can't connect" or a timeout: the host value is wrong or the database server is down
- connection works but no tables: WordPress is pointing to an empty database
Check the tables with WP-CLI
If the connection works, WP-CLI can check the tables using the details from wp-config.php:
wp db checkThe output lists each table with its status. Tables reported as corrupted or crashed point to a damaged database rather than a connection problem.
WP-CLI also offers wp db repair. Use it only after you have a backup of the database, and preferably with your hosting provider or a developer involved if the database is large or the site handles orders.
Use the WordPress repair page only as a last step
WordPress includes a built-in repair tool. To enable it, add this line to wp-config.php, before the line that says "That's all, stop editing":
define( 'WP_ALLOW_REPAIR', true );Then open:
https://example.com/wp-admin/maint/repair.phpImportant: while this line is active, the repair page can be opened by anyone, without logging in. Remove the line from wp-config.php as soon as the repair is complete, and check that the page no longer works.
Make a database backup before running the repair, and do not use it if you are not sure the problem is table corruption.
Check the hosting error logs
Most hosting panels give access to PHP or server error logs. Look for errors recorded at the time the website stopped working, such as refused connections, too many connections or a full disk.
Logs can contain sensitive information. Review them before sharing, and share them only through a secure channel.
D4Hub can help you interpret the results of these checks and decide the safest next step.
FAQFrequently asked questions
Not usually. The most common causes are hosting problems or wrong connection details. A compromise is possible, for example if someone changed wp-config.php or the database password, but it is one possibility among several. If you also notice unknown users, strange redirects or unexpected files, mention it when you ask for help.
An intermittent error often means the database server is overloaded or the account is hitting a connection limit. Traffic spikes, bots, heavy plugins or scheduled tasks can all contribute. The hosting provider can usually see when the limit was reached.
WordPress still has the old password in wp-config.php. The new password must also be written in the DB_PASSWORD line. If you are not comfortable editing the file, your hosting provider or D4Hub can help.
Not as a first step. If the cause is a wrong setting or a database server problem, a restore will not help and may overwrite newer orders, messages or content. Restoring makes sense only after the cause is understood and the backup has been checked.
The built-in repair tool is designed for this, but back up the database first and remember to remove the WP_ALLOW_REPAIR line afterwards. If the site handles orders or customer data, consider asking for support before running it.
This usually means WordPress is connected to a database that is empty or different from the original, or that the table prefix in wp-config.php does not match the existing tables. Do not complete the installation. Check the database name and the table prefix, or ask for help.
Yes. Share what the hosting provider told you and what you have already tried. D4Hub can check the configuration, the database and the website itself to find where the connection fails.