Skip to main content

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

· 4 min read
Customer Care Engineer

wordpress-error-establishing-database-connection

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.php in 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:

  1. Open the wp-config.php file in the site root.

  2. Find the lines:

define('DB_NAME', 'database_name');

define('DB_USER', 'username');

define('DB_PASSWORD', 'password');

define('DB_HOST', 'localhost');
  1. 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:

  1. 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.

  1. 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:

wordpress-error-establishing-database-connection

  1. Load Average

  2. Percentage of CPU usage and the amount of RAM in GB in use

  3. 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. 

Repairing a corrupted database

Sometimes the issue is a corrupted database. In that case, you’ll see log entries like:

[ERROR] mysqld: Table 'wp_options' is marked as crashed and should be repaired

[Warning] Checking table:   './wordpress/wp_posts'

[ERROR] Got error 127 when reading table './wordpress/wp_comments'

[ERROR] mysqld: Index for table 'wp_users' is corrupt; try to repair it

 WordPress has a built-in mechanism for repairing corrupted databases. To run it:

  1. Add the following line to wp-config.php:
define('WP_ALLOW_REPAIR', true);
  1. Navigate to https://your-site.com/wp-admin/maint/repair.php.

  2. Choose “Repair Database” or “Repair and Optimize Database.”

  3. When finished, be sure to remove this line from wp-config.php.

warning

It’s important to understand: the repair page only works if the MySQL server is running. If the database server is completely stopped, the site and the repair page will be equally unavailable.

What to do if nothing helps

If the site still doesn’t work, more serious issues are possible:

  • Your hosting provider has limited MySQL resources (relevant on shared hosting)

  • The database is too large and needs optimization

  • Due to natural growth of the DB and site traffic, the server no longer has sufficient resources for stable operation

  • Hardware failure on the server

  • MySQL configuration failure

  • A DDoS attack

In these cases, it’s best to contact hosting support. Professionals will check the server and, if necessary, restore data from a backup.

Conclusion

The WordPress database connection error is alarming, but most often it’s resolved by verifying the connection details or optimizing server load. The main thing is to stay calm and check each step methodically.

And in case of more serious problems, you can always contact our specialists for free technical support or restore your server yourself from backups, which are created automatically every day for all our VPS.