Error library · WordPress
“Error establishing a database connection”: what it means and how to fix it

What it means
Every WordPress page is built from a database: your posts, settings and users all live there. This message means WordPress started up but couldn't connect to that database, so it has nothing to show. Your content is almost always still there. WordPress just can't reach it.
I reproduced it on a test site by pointing WordPress at a database server that wasn't answering. The page above is exactly what visitors get, and WordPress sends it with an HTTP 500 status, so search engines know it's an error rather than your real page.
The usual causes, most likely first
- The login details in
wp-config.phpare wrong. Most common straight after moving the site to a new host, or after someone changed the database password in the hosting panel. - The database server is down or overloaded. On shared hosting, a busy neighbour or a host outage can stop connections for a while.
- The database user lost its permission to use the database, for example after a hosting account change.
- Damaged database tables. This usually shows a different message in wp-admin: "One or more database tables are unavailable."
How to fix it, in a safe order
- Check whether it's your host. Look at your host's status page or ask their support whether MySQL is down on your server. If it is, there's nothing to fix on your side. Wait, and the site comes back by itself.
- Open
wp-config.php(in the same folder aswp-content) with your host's file manager. Download a copy before changing anything. Find these four lines:define( 'DB_NAME', '...' ); define( 'DB_USER', '...' ); define( 'DB_PASSWORD', '...' ); define( 'DB_HOST', '...' );
- Compare them with your hosting panel. In the Databases section, check that the database name and user exist and match exactly, prefix included (many hosts add one, like
u12345_). - Reset the database user's password in the panel, and paste the new one into
DB_PASSWORD. This fixes most cases after a move or a password change. - Check
DB_HOST. It'slocalhoston most hosts, but some give you a separate address or port. Your host's database page shows the right one. - Only if wp-admin says tables are unavailable: add
define( 'WP_ALLOW_REPAIR', true );towp-config.php, visit/wp-admin/maint/repair.php, and run the repair. Remove the line straight afterwards: while it's there, anyone can open that page.
Test the database login with a small file
Not sure whether the details are right? This tells you in one page load. Create a file called db-test.php next to wp-config.php, paste this in, and fill in the same four values:
<?php
$db = @mysqli_connect(
'DB_HOST value',
'DB_USER value',
'DB_PASSWORD value',
'DB_NAME value'
);
echo $db ? 'Connected: the details are right.'
: 'Failed: ' . mysqli_connect_error();
Open yoursite.com/db-test.php. “Access denied” means the user or password is wrong. “Unknown database” means the name is wrong. “Connection refused” or a timeout points at the host or DB_HOST. Delete the file straight afterwards: it contains your database password.
On localhost: XAMPP, MAMP or Local
- XAMPP: open the XAMPP Control Panel and check MySQL is started; it often fails because another program is using port 3306. A fresh XAMPP install uses the user
rootwith an empty password. - MAMP: MySQL runs on port 8889 by default, so
DB_HOSTneeds to belocalhost:8889. The default user and password are bothroot. - Local: the site has to be started in the Local app before its database answers.
- On a Mac or Linux, if
localhostfails, try127.0.0.1. The first connects through a socket file, the second over the network, and one sometimes works when the other doesn't.
Where your hosting panel keeps the database details
- cPanel (many hosts, including GoDaddy and Namecheap): MySQL Databases lists databases and users, and lets you reset a password and re-add a user to a database.
- Hostinger hPanel: open your website, then Databases → Management.
- Plesk: Databases, then the database's User Management.
Why the error comes and goes
If the site works most of the time and shows this message now and then, the details are fine. The database is refusing some connections: usually a traffic spike, bots hammering the site, or a hosting plan's limit on simultaneous connections. Caching cuts the number of database connections a lot; a bigger plan or a better host fixes the rest.
Still not working?
If the details are right and the host says the server is fine, the problem is usually the database user's permissions or a limit on connections. Both need someone looking at the hosting account itself.
Rather not touch the files?
I'll fix it for a fixed $129, with a backup first and a note of what broke. If I can't fix it, you don't pay.
Fix my site · $129FAQ
Questions people ask
What does “error establishing a database connection” mean?
WordPress started, but couldn't log in to the database that holds your posts, pages and settings, so it has nothing to show. The content is almost always still there.
Is my content lost?
Almost never. The error means WordPress can't reach the database, not that the database is gone. Once the connection works again, everything comes back as it was.
Why does the error come and go?
When it's intermittent, the login details are fine and the database is turning away some connections, usually during traffic spikes or because of a connection limit on your hosting plan.
Can a plugin cause it?
Rarely directly. A plugin that runs very heavy database work can use up connections, and a hacked site sometimes has its wp-config.php changed. Check the four database lines first either way.
Will it hurt my Google rankings?
Not for a short outage. WordPress sends the error with a 500 status, which tells Google it's temporary. Errors that last days can make Google crawl less and drop pages, so fix it quickly.