Quick answer
This error means WordPress cannot connect to the MySQL database, so it cannot load the site. The most common culprits are incorrect details in `wp-config.php`, an unavailable MySQL server, or a deleted database user. Check the database details first, then repair tables.
How to recognize the problem
- The site shows the message "Error establishing a database connection"
- You cannot log in to `/wp-admin`, the same error appears
- The site was working yesterday, but now it is completely unavailable
- The error appeared after changing a password or moving the site to another host
Most common causes
Incorrect details in wp-config.php
The database name, user, password, or host have been changed or mistyped. WordPress then cannot log in to the MySQL server.
MySQL server is unavailable
The database server has crashed, been restarted, or reached its connection limit. In that case, the error affects all sites on the same host.
Database user deleted or password changed
Someone deleted the user in the hosting panel, removed its privileges, or changed the password, and `wp-config.php` was not updated.
Corrupted or incomplete database
An interrupted import, disk failure, or failed backup can leave the database in a state where WordPress cannot connect.
Wrong host or port
After moving to another server, the old `DB_HOST` remains, for example `localhost` instead of the server name required by the host.
Step-by-step fix
- 1
Note the exact error message
Open the site and copy the entire message, including any error number. If only a general message is visible, save a copy of
wp-config.php, then temporarily enable error display with the linesdefine('WP_DEBUG', true);anddefine('WP_DEBUG_DISPLAY', true);. Do this only briefly and not on a public site, because visitors can see the messages; be sure to turn them off afterwards. The exact text greatly narrows down the cause. - 2
Check if the MySQL server is alive
In the hosting panel (cPanel, Plesk, or similar) or on the hosting status page, check if the MySQL service is available and if the resource limit has been reached. If the server is down or the connection limit is reached, wait for recovery or contact hosting support. If other sites on the same host are working, the problem is likely in your database.
- 3
Open wp-config.php and check the details
Using an FTP client or the file manager in the panel, open
wp-config.phpin the site root. Compare the values ofDB_NAME,DB_USER,DB_PASSWORD, andDB_HOSTwith the details in the hosting panel. Pay attention to spaces, upper and lower case, and whether the password is in quotes. - 4
Check the database user and privileges
In the hosting panel, open the MySQL databases and users section. Make sure the user from
wp-config.phpexists, is assigned to that exact database, and has all privileges. If not, assign it again or reset the password and enter the new one inwp-config.php. - 5
Check DB_HOST and port
If the host uses a separate database server,
DB_HOSTis notlocalhost, but the name or IP address provided by your host, sometimes with a port in the formserver_name:3306. Look for the exact value in the hosting documentation or panel and copy it towp-config.php. - 6
Make a backup before further changes
Before touching the database, download a copy of the files and export the database via phpMyAdmin or the hosting tools. Also save a copy of
wp-config.php. That way you can revert to the previous state if something goes wrong. - 7
Check if the database and tables exist
In phpMyAdmin, check if the database with the name from
wp-config.phpexists and if it contains tables with a prefix matching$table_prefix. If the tables are empty or missing, the database was probably deleted or the import failed. - 8
Repair tables if they are corrupted
In phpMyAdmin, select the tables, then choose the repair option (
Repair table). If repair does not help, restore the database from the last backup. After restoring, check the details inwp-config.phpagain. - 9
Test the site and disable debug
Open the site and
/wp-adminin an incognito browser window. If it loads, remove theWP_DEBUGandWP_DEBUG_DISPLAYlines or set them tofalse. If the error persists, go back to the step checking the user and host.
If nothing helps
If the details in wp-config.php are correct, the user and privileges are proper, and the database exists, the problem is most likely on the server side. In that case, open a ticket with your host and provide the exact error message, the time it started, and whether you changed anything immediately before. If the database is corrupted, the host can restore the last backup, but you will lose content created after it. For sites with WooCommerce, also check if the database has reached its size or connection limit, because then the error starts appearing intermittently, and only then constantly.
How to prevent it
- Regularly make automated backups of the database and files and verify that they can be successfully restored
- Do not change the database user password without simultaneously updating it in `wp-config.php`
- Keep a record of database details before every site migration
- Monitor MySQL resource usage and connection count in the hosting panel
When to call a professional
If you cannot access the hosting panel, do not know the exact database details, or the database is corrupted, it is better to contact IT support than to modify tables yourself and risk data loss.
Website development · Fast, SEO-ready, multilingual websitesFAQ
Does a database error mean the site is permanently lost?
No. In most cases, the site and content are intact, WordPress just cannot connect to the database. If the details in `wp-config.php` and the database user match, the site returns without content loss.
How do I know if the problem is in my database or on the server?
If other sites on the same host are working, the problem is in your database or access details. If they are not working either, the MySQL server is probably down and only hosting support can help.
Can I repair the database without phpMyAdmin?
You can if the host offers a database repair tool in the panel or if you have command-line access. Without that, the safest option is to restore the database from a backup or ask your host to do it.