Every WordPress page is built from content stored in a database. When WordPress can't reach that database, it can't show anything at all, and your visitors see a single line: "Error establishing a database connection." If your site, or a fresh install, is stuck on this message, this article will help you.
We are here to help you find out exactly why the connection fails and fix it, step by step. It is one of the most common problems new site owners face. When we checked the WordPress.org Installing WordPress support forum on November 30, 2026, five of its 92 most recent threads were about a database connection failure.
Related Articles
- How To Fix "There Has Been A Critical Error On This Website"
- How To Create A Database Using phpMyAdmin
- How To Back Up And Restore WordPress
What "Error Establishing A Database Connection" Means
WordPress keeps your posts, pages, users and settings in a MySQL or MariaDB database. On every visit, it connects using four details from your wp-config.php file: the database name, username, password and host. If any of them is wrong, or the database server isn't answering, WordPress stops and shows this error.
The WordPress documentation lists three main causes: wrong details in wp-config.php, a problem with your web host's database server, and a hacked site.
What We Saw When We Reproduced It
We ran a copy of WordPress 7.1.4 on our computer with PHP 8.4. Then we pointed its wp-config.php at a database server that wasn't running. Visitors saw only one line, with no clue about the cause.

Next, we turned on WP_DEBUG. Now the same page showed the real reason, "Connection refused", plus a short checklist from WordPress itself.

Where I Have Seen This Error
I have run many WordPress sites on different hosts, and this error has come up for different reasons. On GoDaddy Managed WordPress hosting, we saw it regularly, and their support team fixed it for us. On SiteGround, I saw it when my plan ran short of resources: the server stopped responding whenever I published a new article, and their support suggested upgrading to a plan with more resources and RAM. On a KnowHost VPS 1 plan, adding more RAM fixed it.
So don't assume the problem is in your own files. Sometimes the database server is simply overloaded, and only your host can see that.
Quick Checklist
- Compare the four database details in
wp-config.phpwith your hosting panel. - Test the connection with a small file to see the exact reason.
- Ask your host whether the database server is down or overloaded.
- Repair the database if WordPress says tables are unavailable.
- Check that nobody changed
wp-config.phpwithout you.
Step 1: Check The Database Details In wp-config.php
First, open wp-config.php in your host's File Manager. Find these four lines:
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_user' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' );
Next, open the databases page in your hosting panel and compare every value letter by letter. The host is often localhost, but some hosts use a separate database server, so copy the exact host name from your panel. If you recently changed the database password in your panel, update it here too.
Step 2: Test The Connection With A Small File
To see the exact reason, create a file called db-test.php in the same folder as wp-config.php, with this code:
<?php
$link = @mysqli_connect( 'localhost', 'your_database_user', 'your_database_password', 'your_database_name' );
echo $link ? 'Connected to the database.' : 'Could not connect: ' . mysqli_connect_error();
Now open yoursite.com/db-test.php in your browser. On our test copy, it said "Could not connect: Connection refused". Here is what the common messages mean, based on the MySQL error reference:
- Connection refused, or Can't connect to MySQL server: the database server is down, or the host name or port is wrong.
- Access denied for user: the username or password is wrong, or the user hasn't been given access to the database.
- Unknown database: the database name is wrong, or the database doesn't exist yet.
Delete db-test.php as soon as you have your answer, because it contains your database password.
Step 3: Check If The Database Server Is Down Or Overloaded
If the details are correct but you still get "Connection refused", the problem is on the server. Check your host's status page, then contact their support and ask whether the database server is running. If the error appears only at busy times, your plan may be running out of memory, as it did on my SiteGround and KnowHost plans.
Step 4: Repair The Database
If your dashboard says "One or more database tables are unavailable", the database may be damaged. Take a backup first. Then add this line to wp-config.php, just above "That's all, stop editing!":
define( 'WP_ALLOW_REPAIR', true );
Now open yoursite.com/wp-admin/maint/repair.php and click Repair Database.

Remove the line straight after. The wp-config documentation warns that anyone can open the repair page while it is switched on, without logging in.
Step 5: Check For Unexpected Changes
If the details in wp-config.php look different from what you set, and nobody on your team changed them, treat it as a possible hack. Compare the file with your latest backup, change your hosting and database passwords, and restore a clean copy of the site if anything else looks wrong.
Getting The Error While Installing WordPress
All five forum threads we counted were in the Installing WordPress forum, so many people hit this error while installing WordPress. In that case, create the database and a database user in your hosting panel first, give the user all privileges on that database, and then run the installer. Our guide to creating a database with phpMyAdmin shows how. On a local setup such as XAMPP, make sure the MySQL service is started, because a stopped server gives the same "Connection refused" we saw.
Common Mistakes To Avoid
- Copying a password with a space at the end: the extra space makes the password wrong. Paste it carefully between the quotes.
- Editing wp-config.php in a word processor: it can turn straight quotes into curly ones and break the file.
- Forgetting the repair line: leaving
WP_ALLOW_REPAIRon lets anyone run the repair page. - Leaving the test file online: always delete
db-test.phpwhen you are done.
How To Prevent It
- Keep your database details in a password manager, so you never retype them from memory.
- Update
wp-config.phpon the same day you change a database password in your hosting panel. - Set up an uptime monitor that emails you when your site goes down.
- Choose a hosting plan with enough memory for your traffic, and upgrade before busy periods.
Error Establishing A Database Connection: FAQs
Have I lost my posts?
Almost certainly not. The error means WordPress can't reach the database, not that the data is gone. Once the connection works, everything returns.
Why does the error come and go?
An error that appears only at busy times usually means the database server is overloaded. Ask your host about your plan's limits.
Could this mean my site was hacked?
It can. If wp-config.php has changed and you didn't change it, restore a clean backup and read our guide on what to do when your WordPress site is hacked.
Final Words
An error establishing a database connection always comes down to the four details in wp-config.php or the database server behind them. Check the details, test the connection, and ask your host if the server is the problem. Let us know in the comments what caused the error on your site.
Sources
We checked these sources for this guide on November 30, 2026:
- Common WordPress errors, WordPress.org Documentation
- Editing wp-config.php, WordPress Developer Resources
- Server error message reference, MySQL 8.4
- Installing WordPress forum, WordPress.org Support




