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.

Share this post
8 min read

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.
Before you start. The WordPress debugging guide advises a backup or a staging copy before you change your site. Save a copy of wp-config.php before you edit it.

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?

CauseTypical signWhat to do
Wrong details in wp-config.phpStarted after a move, a new host or a password changeMatch the four lines to your hosting panel
Database server downStarted on its own, other sites on the host also failContact your host
Database over its quotaHost emails about limits, large databaseContact your host
Damaged database tableswp-admin says tables need repairUse the repair page, then turn it off
Hacked siteNothing else explains itScan 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' );
  1. Open the databases section of your hosting panel.
  2. Compare the database name with DB_NAME, letter for letter.
  3. Compare the database user with DB_USER.
  4. Check that this user is assigned to that database.
  5. Check DB_HOST. Many hosts use localhost, but some give a separate host name.
  6. 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.

Password not working? WordPress suggests resetting the database password if you are sure the other details are right. Set a new password in your hosting panel, then put the same password in DB_PASSWORD.
0 of 2AI Overview answers Digieh checked, on Google and Bing, mention the hacked-site cause or the repair page risk. Both are in the WordPress handbook.

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.

FormatExampleWhen it is used
Host namelocalhostDatabase on the same server
Host and portdb.example.com:3307Database on a custom port
Host and socketlocalhost:/tmp/mysql.sockConnection through a socket file
IPv6 address[::1]:3306Address 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.

Turn it off right after. The wp-config.php handbook says nobody needs to log in to use this page while it is on. It should only be on when needed and off once the issue is solved. Delete the line or set it to false.

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.

  1. Open the databases section of your hosting panel.
  2. Find the database user named in DB_USER.
  3. Choose the option to change its password and set a new one.
  4. Copy the new password into DB_PASSWORD in wp-config.php.
  5. 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.

Try this today. Download a copy of wp-config.php and keep it somewhere safe. It is the first file you will need if this error appears.

Test Yourself

What does WordPress say usually causes this error?

  1. A mistake in wp-config.php
  2. A slow internet connection
  3. 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?

  1. It slows down the site
  2. Anyone can open the repair page without logging in
  3. 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

Found this useful?

Share this post
Avatar photo

Syed Wasif Raza

Syed Wasif Raza is the founder and editor of Digieh. He writes about health, food, lifestyle, news and sports in plain, easy English. Every guide he publishes is checked against official sources such as government and health agency pages. Connect with him on LinkedIn.

Articles: 891

Leave a Reply

Your email address will not be published. Required fields are marked *