WordPress error establishing a database connection: what it means and how to fix it

If you’ve ever seen the “Error establishing a database connection” message on your WordPress site, you know how unpleasant it is. The site stops working, visitors see nothing but a white screen with that phrase, and anxiety gradually rises. In reality, this is one of the most common WordPress issues, and it can be fixed without panic or hiring outside specialists.
What is the “error establishing a database connection”?
WordPress runs on a PHP + MySQL/MariaDB stack. All your posts, pages, comments, and settings are stored in a database. When the CMS can’t connect to the database, the site simply doesn’t know where to get its data from. As a result, this error appears.
There are several possible causes:
-
Incorrect connection details (username, password, database name) in the
wp-config.phpin the site’s root directory. -
Problems with the database server, such as MySQL/MariaDB overload or a crash.
-
A corrupted database, which sometimes happens after a failed WordPress update or an abrupt server shutdown.
-
Network restrictions or hosting issues that block the connection (if the DB connection is made over the network rather than locally).
How to check your connection details
The first thing to do is make sure WordPress has the correct database credentials:
-
Open the
wp-config.phpfile in the site root. -
Find the lines:
define('DB_NAME', 'database_name');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
- Verify that all values match the settings specified when the database was created. Sometimes the issue comes down to a simple typo.
For example, in the FASTPANEL control panel you can find the connection parameters under “Management” → “Databases”.
If you don’t remember the correct DB credentials, you can change the password yourself by following the instructions in this article. Or contact technical support for assistance.
Checking the database server
If the credentials are correct but the error persists, check the MySQL server itself:
- Try connecting to the database directly via phpMyAdmin or the MySQL CLI.
To connect using the CLI, log in to the server via SSH and run:
mysql -u user -p
Replace user with the username from wp-config.php, then enter the password. If the connection succeeds, you’ll see output similar to:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10498
Server version: 8.0.41 MySQL Community Server - GPL
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
This means the database server is operating correctly, and the database connection problem lies elsewhere. Carefully review the MySQL logs as well as the other tips in this article.
- If the connection can’t be established, the server may be overloaded or temporarily unavailable. In this case, you can contact your hosting support or restart MySQL/MariaDB.
To check whether the MySQL service is running, run:
systemctl status mysql
If the service is running, you’ll see a message like:
Active: active (running) since Wed 2025-08-20 20:40:25 UTC; 14h ago
Otherwise you’ll see:
Active: inactive (dead) since Thu 2025-08-21 11:18:47 UTC; 865ms ago
There are many possible reasons for this MySQL service status - from lack of resources to configuration errors. To investigate, you can check the logs in the system journal or in /var/log/mysql/error.log.
Next, make sure the server’s hardware resource usage is within normal limits. To do this, use the htop utility. It may not be installed on your OS by default. To install it, run:
For Debian/Ubuntu:
sudo apt update && sudo apt install htop
For CentOS/AlmaLinux/Rocky Linux:
sudo yum install htop
Then run:
htop
An interactive window will open. Focus on the three main interface areas marked in the screenshot:

-
Load Average
-
Percentage of CPU usage and the amount of RAM in GB in use
-
Top processes consuming the most resources
We won’t dive into these metrics in detail here. The key point is that high values for any of them indicate the server can’t handle the current load - which is likely the reason your site’s database is unavailable.
Often, the culprits behind high load are search crawlers that send too many requests to your sites. To try resolving this on your own, use this article.
If the load is normal, try starting the MySQL service again:
sudo systemctl restart mysql
Even if the server starts without errors after this, be sure to review the logs yourself or with the help of technical support. Otherwise, the situation may recur at the most unexpected moment with unpredictable consequences.