Error Establishing a Database Connection in WordPress
Find out if your host is down, wp-config.php is wrong or the database is damaged, try the fixes in order, and copy a message for your host.
Published 1 December 2026
This error means WordPress is running but cannot use its database, where your pages, products and orders are saved. Open yourdomain.com/wp-admin/ and read the longer message there. It usually points to one of three causes: the database server, the login details in wp-config.php, or damaged tables. The message itself does not mean your content is deleted.
Read the longer message first
Visitors see one short line. WordPress shows more detail on the admin address, so use /wp-admin/ and not /wp-login.php. Match what you see:
- The username and password may be wrong, or the server could not be contacted: do check 1, then check 2.
- Cannot select database: the username and password work. The database name is wrong, or that user has no permission to open it. Go to check 2.
- One or more database tables are unavailable: WordPress can log in, but it cannot read some tables. Go to check 3.
If the admin address shows no extra detail, your site may have its own error page. Do the checks in order.
Stop if a WordPress setup page asks for a language, site title or new username. Do not fill it in. The database may be empty, or its name or the $table_prefix line may be wrong in wp-config.php. Anyone who opens the site can complete that page and take control. If it appeared after your edit, put your saved file back at once. If not, ask your host to block the site while they check.
Load-shedding or weak mobile data is not the cause. They can stop a page from opening, but this message came from your hosting server.
Check 1: is the database server down?
- Open the web address of a picture on your site, such as your logo, in a private window. If it opens but pages fail, the web server is working. If you use a CDN, this can be a saved copy, so do not rely on this test alone.
- Log in to your hosting panel. Look for a suspended account, an expired plan, a full disk or a database that has reached its limit.
- Open phpMyAdmin from the panel. If it shows your tables, the database server is running, so go to check 2. If it cannot connect, or your database is missing or empty, message your host. Do not create a new database.
- Open another WordPress site on the same hosting account, if you have one. If both fail together, suspect the server.
If nothing on the site opens at all, use these checks for a website that will not open instead.
Check 2: do the four database lines match?
Backup first: download a copy of
wp-config.phpfrom File Manager. If phpMyAdmin opens, export the database too. Keep both private. Do not leave a copy such aswp-config.txton the server, because visitors may be able to open it and read your database password.
The file is in your main WordPress folder, often public_html. It can also be one folder above. Find these four lines (example with made-up values):
define( 'DB_NAME', 'shop_wp1' );
define( 'DB_USER', 'shop_user1' );
define( 'DB_PASSWORD', 'your-database-password' );
define( 'DB_HOST', 'localhost' );
Compare them with the database page in your hosting panel:
- Name: check every letter. Some hosts add your account name at the start, so
wp1becomesshop_wp1. - User: it must exist and have permission on this database. Creating a user and adding it to a database can be two separate steps.
- Host:
localhostis common, but some hosts use another name or a port number. Copy theirs, do not guess. - Password: if the first three are right, set a new password for the database user, then put the same one in the file straight away. Any other site using that user stops working until you update it too.
Use a long random password made of letters and numbers. A quote mark or backslash inside it can break the line. Edit in File Manager or a plain text editor, not in Word, which can change straight quotes into curly ones.
Save and test. If nothing improved, undo your edits to the name, user and host. If you changed the password, keep the new one in the file.
After a move, the file may still have the old host's details.
Check 3: are the tables damaged?
Do this only if /wp-admin/ says tables are unavailable.
Backup first: export the whole database in phpMyAdmin and download
wp-config.php. If you cannot export the database, ask your host for a copy and stop here until you have it.
This line turns on the WordPress repair page for a short time:
define( 'WP_ALLOW_REPAIR', true );
Use it in this order:
- Add the line to
wp-config.php, above the comment that tells you to stop editing. - Open
yourdomain.com/wp-admin/maint/repair.phpand press Repair Database. - Read the result for each table and take a screenshot.
- Delete the line from
wp-config.phpstraight away, even if the repair failed or the page stopped. While it is there, anyone can use the repair page without logging in. - Open the repair page again. It should now tell you to add the line, and the button should be gone. If the button is still there, the line is still on.
The repair command works only on some table types. If a table could not be repaired, do not keep pressing the button. Ask your host. You can also restore a tested backup, but orders made after it will be missing.
If your settings and your host's server are both fine, WordPress says the site may have been hacked. Follow the first-hour plan for a hacked site.
What to send your host
Change the made-up details in this example. Never put your database password in a ticket, email or WhatsApp message.
Subject: WordPress cannot connect to its database
Website: yourdomain.com
Started: 1 December 2026, about 9:15 am Pakistan time
Happens: all the time / comes and goes
Message on /wp-admin/: (screenshot attached)
phpMyAdmin: opens / does not open
Database name: shop_wp1
Database user: shop_user1
Last change: moved hosting / changed password / update / nothing
Please check:
1. Is the database server running for my account?
2. Has my disk, database or plan reached a limit?
3. Does this user have permission on this database?
4. What is the correct database host name?
5. Are any tables damaged? Please make a backup before any repair.
If the same limit keeps stopping your site, ask your host which plan has a higher one. Before you move, our WordPress hosting guide explains what else to check, such as backups and the renewal price.
Common questions
Can I lose my orders because of this error?
The connection error does not delete orders. You can lose data if tables are badly damaged, or if you restore an old backup over newer orders. Export the database before any repair. Before any restore, note every order placed since that backup was made.
Why does the error come and go?
The database server may be overloaded, or your account may be reaching a limit at busy times. Write down the exact times and send them to your host, who can compare them with the server records.
Should I turn off my plugins?
It is rarely the first fix here. WordPress connects to its database before it loads normal plugins, so a wrong password stays wrong when plugins are off. A heavy plugin can still overload the database. Ask your host which queries were slow.
Will reinstalling WordPress fix it?
Not if the password is wrong or the database server has stopped. Some one-click installers may also replace what is already in the folder. Leave them alone until you know the cause and have a backup of both the files and the database.
Sources
- WordPress: Common WordPress errors
- WordPress: wp-config.php database settings
- WordPress: Editing wp-config.php, including database repair
- WordPress code reference: how the database error page works
- WordPress code reference: when the setup page opens
- MySQL: REPAIR TABLE