Error Establishing a Database Connection: How to Fix
Fix "Error establishing a database connection" in WordPress. Check your wp-config.php lines with our free checker, then the host, repair and hack causes.

Last updated December 1, 2026
“Error establishing a database connection” means WordPress cannot reach its database. WordPress says a mistake in wp-config.php is the usual cause. A database server that is down, or a database your host has shut off, can also cause it.
This guide checks each cause in order. It starts with the four lines in wp-config.php that cause most cases.
Key Takeaways
- Check DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php against your hosting panel.
- Curly quotes, a missing semicolon or an extra space can break those lines.
- If the settings are right, ask your host if the database server is down or over its quota.
- The WordPress repair page works without a login while it is turned on. Turn it off when done.
- If nothing explains it, WordPress suggests checking whether the site was hacked.
What Does “Error Establishing a Database Connection” Mean?
WordPress keeps your posts, pages and settings in a MySQL or MariaDB database. On every page load, it logs in to that database using details in wp-config.php. If that login fails, you see this error instead of your site.
WordPress core asks three questions when the connection fails. Are the username and password correct? Is the hostname correct? Is the database server running?
| Cause | Typical sign | What to do |
|---|---|---|
| Wrong details in wp-config.php | Started after a move, a new host or a password change | Match the four lines to your hosting panel |
| Database server down | Started on its own, other sites on the host also fail | Contact your host |
| Database over its quota | Host emails about limits, large database | Contact your host |
| Damaged database tables | wp-admin says tables need repair | Use the repair page, then turn it off |
| Hacked site | Nothing else explains it | Scan the site, follow a hacked site guide |
Source: Digieh summary of the WordPress common errors page and the core connection message. Read December 1, 2026.
How Do You Check the Database Details in wp-config.php?
Open wp-config.php in your site’s root folder with your host’s file manager or FTP. Find these four lines:
define( 'DB_NAME', 'database_name_here' );
define( 'DB_USER', 'username_here' );
define( 'DB_PASSWORD', 'password_here' );
define( 'DB_HOST', 'localhost' );- Open the databases section of your hosting panel.
- Compare the database name with DB_NAME, letter for letter.
- Compare the database user with DB_USER.
- Check that this user is assigned to that database.
- Check DB_HOST. Many hosts use localhost, but some give a separate host name.
- Save the file and reload your site.
Paste your lines into the checker below. Swap your real password for xxxx before you paste.
wp-config database lines checker
Paste the four database lines from wp-config.php. Replace your real password with xxxx first. Everything stays in your browser.
Digieh tool. It checks format only. It cannot tell if a name or password is correct. Compare the values with your hosting panel.
Why Do Curly Quotes Break wp-config.php?
PHP only understands straight quotes, like ‘ and “. Word processors and some notes apps swap them for curly quotes as you type. PHP cannot read a line with curly quotes, so the database details never load.
This often happens when someone copies the lines from a document or an email. Always edit wp-config.php in a plain text editor or your host’s file editor. The checker above flags curly quotes for you.
A missing semicolon or a stray space inside the quotes causes the same kind of trouble. A space at the end of a password, for example, makes it a different password.
What Formats Can DB_HOST Use?
WordPress core accepts a few formats for DB_HOST. The most common is a plain host name.
| Format | Example | When it is used |
|---|---|---|
| Host name | localhost | Database on the same server |
| Host and port | db.example.com:3307 | Database on a custom port |
| Host and socket | localhost:/tmp/mysql.sock | Connection through a socket file |
| IPv6 address | [::1]:3306 | Address in brackets, then the port |
Source: Digieh read parse_db_host in WordPress core class-wpdb.php on December 1, 2026.
DB_HOST never starts with http. If your host gave you a different host name, use it exactly as written.
Free updates
Join the Digieh list
Be the first to know when our weekly brief launches.
No spam. Unsubscribe anytime. Read our Privacy Policy.
What If the Details Are Correct?
Then the problem is probably on the server. WordPress names two hosting causes. The database may have hit its quota and been shut down, or the server may be down.
Contact your host and ask both questions. Tell them when the error started and whether you changed anything.
- Note the time the error started
- Note any recent changes (move, update, password)
- Check if other sites on the same host work
- Ask your host about database server status
- Ask about database quota or limits
What caused your database connection error?
- Wrong wp-config.php details
- Host or server problem
- Damaged tables
- Not sure
How Do You Repair the WordPress Database?
If wp-admin says your tables need repair, WordPress has a built-in tool. Add this line to wp-config.php:
define( 'WP_ALLOW_REPAIR', true );Then visit yoursite.com/wp-admin/maint/repair.php and choose a repair option.
You can also repair tables in phpMyAdmin from your hosting panel. If you are not comfortable with that, WordPress suggests asking your host to run the repair.
How Do You Reset the Database Password?
WordPress suggests a manual reset when you are sure the other details are right. The exact menu names differ by host, but the steps are similar.
- Open the databases section of your hosting panel.
- Find the database user named in DB_USER.
- Choose the option to change its password and set a new one.
- Copy the new password into DB_PASSWORD in wp-config.php.
- Save the file and reload your site.
Use a long, unique password. Keep it in a password manager, not in a document.
Could a Hacked Site Cause This Error?
Yes, it can. WordPress lists it as the last cause to check, after wp-config.php and your host. It suggests scanning with Sucuri SiteCheck, a free online scanner.
If the scan finds a problem, follow a hacked site cleanup guide or ask your host for help. Change your database and admin passwords after the cleanup.
Is your site showing a blank white page instead of this message? Our WordPress white screen of death guide helps you tell the errors apart.
Does This Error Happen on a Local Site Too?
Yes. On a local setup, the error can mean the database service is not running. Start MySQL or MariaDB in your local tool, then reload the page.
Local tools may use their own default user and password. Check the tool’s settings rather than guessing.
How Can You Prevent Database Connection Errors?
- Keep a recent backup of your files and database.
- After a move or password change, update wp-config.php right away.
- Edit wp-config.php in a plain text editor, never a word processor.
- Watch your hosting panel for database limits.
- Use strong, unique passwords for your database and admin accounts.
For other WordPress problems, see our WordPress critical error guide. Strong sign-ins matter too, so read our passkeys guide. Running a business site? Our Google Business Profile setup guide helps customers find you.
Test Yourself
What does WordPress say usually causes this error?
- A mistake in wp-config.php
- A slow internet connection
- Too many images
The WordPress common errors page says the error is usually caused by an error in wp-config.php.
Why should you turn off WP_ALLOW_REPAIR after using it?
- It slows down the site
- Anyone can open the repair page without logging in
- It deletes posts
WordPress says no login is needed while it is on. So turn it off once the issue is solved.
Frequently Asked Questions
Why did this error appear after I moved my site?
The new host likely uses a different database name, user, password or host. Update all four lines in wp-config.php to match the new hosting panel.
Can a plugin cause this error?
The WordPress common errors page does not list plugins as a cause. It points to wp-config.php, your host and a hacked site.
Is my content lost?
Not necessarily. The error means WordPress cannot reach the database, not that the data is gone. Your host can confirm the database still exists.
Why does the error come and go?
An error that comes and goes can point to the server side. Ask your host about database limits and server status.
Conclusion
This error means WordPress cannot log in to its database. Check the four lines in wp-config.php first. Then ask your host about the server and quota. Repair damaged tables if needed, and scan for a hack last.
Editor’s Note
This guide is accurate as of December 1, 2026. We checked the WordPress developer handbook and WordPress core code on that date. Hosting panels differ, so your host’s steps may look different.
Spot an error in this article? Please contact us at support@digieh.com or read our Corrections Policy.
Keep exploring
Your next read is waiting
1Home & KitchenWhirlpool Dishwasher Error Codes: Blink Patterns and Fixes11 min read
2AI & TechWordPress 500 Internal Server Error: How to Fix7 min read
3Science & DiscoveriesSolar Eclipse 2027: Exact Times for 60 Cities8 min read
4HealthGanglion Cyst on the Wrist: Causes and Treatment7 min read
5MedicinesIs Sugar an Electrolyte? The Simple Science Answer7 min read
6Food & Lifestyle2027 Weekly Planner: Free Dated Printable PDF Pages8 min readFound this useful?












