How to Fix WordPress Error Establishing a Database Connection (5 Steps)

WordPress Error Establishing a Database Connection – 5 Steps to Fix

Post Date: March 20, 2021
Last Updated: November 29, 2026

Introduction

The WordPress Error Establishing a Database Connection message occurs when WordPress cannot communicate with its database. WordPress uses MySQL or MariaDB to store website content, user details, settings, posts, pages, and other important information.

When the database connection fails, your website may display an error instead of loading its content. This issue can occur due to incorrect database credentials, a stopped database service, corrupted database tables, or temporary server problems.

In this blog, we will explain how to troubleshoot and fix the WordPress database connection error using simple steps.

Prerequisites

Before troubleshooting, make sure you have the following:

  • Access to your website’s hosting account or server.
  • FTP, SSH, or File Manager access to WordPress files.
  • Access to the wp-config.php file.
  • Database name, username, and password.
  • Access to MySQL or MariaDB, if you manage the server.

How to Fix WordPress Error Establishing a Database Connection

Step 1: Check the Database Credentials in wp-config.php

Incorrect database credentials are one of the common causes of this error. WordPress stores its database connection information inside the wp-config.php file, located in the website’s root directory.

Open wp-config.php and verify the following settings:

define('DB_NAME', 'database_name');
define('DB_USER', 'database_username');
define('DB_PASSWORD', 'database_password');
define('DB_HOST', 'localhost');

Make sure the database name, username, password, and database host are correct. If you are using a hosting environment, verify that the database and user exist and that the user has the necessary privileges.

Save the file after correcting any incorrect values and reload your website.

Step 2: Check Whether the Database Server Is Running

If the credentials are correct, the database service may be stopped or unavailable. On Linux servers, check the MySQL or MariaDB service status:

systemctl status mariadb

If your server uses MySQL, run:

systemctl status mysql

If the service is stopped, start it using the appropriate command:

systemctl start mariadb

Check the service logs for errors if it fails to start.

Step 3: Test the Database Connection

Try connecting to the database manually to verify whether the database credentials are working.

mysql -u database_username -p -h localhost

Enter the database password when prompted. If the connection succeeds, check whether the required database exists and the user has appropriate permissions.

If the connection fails, review the error message for incorrect credentials, connection issues, or database server problems.

Step 4: Repair the WordPress Database

Sometimes database tables become corrupted, causing WordPress to fail. WordPress provides a built-in database repair feature.

Add the following line to your wp-config.php file:

define('WP_ALLOW_REPAIR', true);

After adding the setting, access the following URL in your browser:

https://yourdomain.com/wp-admin/maint/repair.php

You will see options to repair the database or repair and optimize it. Select the appropriate option and wait for the process to complete.

Important: Once the repair is finished, remove WP_ALLOW_REPAIR from wp-config.php. This page can be accessed without logging in while the setting is enabled.

Step 5: Contact Your Hosting Provider

If the error persists after checking the configuration and database service, the issue may be related to server resource limits, database server outages, connection limits, or underlying database corruption.

Contact your hosting provider or server administrator and ask them to check the database server status, error logs, disk space, and database connectivity.

Need Help Fixing WordPress Database Issues?

Facing persistent database connection errors, website downtime, or unexpected WordPress issues? Contact Pheonix Solutions for expert assistance with WordPress troubleshooting, database errors, website maintenance, and security.

Conclusion

The WordPress Error Establishing a Database Connection can occur due to incorrect database credentials, a stopped MySQL or MariaDB service, corrupted database tables, or server-side issues. By checking wp-config.php, verifying database services, testing connectivity, and repairing the database, you can resolve many common connection problems.

Always take a backup of your WordPress files and database before making any changes to prevent accidental data loss.

FAQs

1. Why does WordPress show an error establishing a database connection?

This error usually occurs when WordPress cannot connect to its database due to incorrect credentials, database server downtime, corrupted tables, or server resource issues.

2. Where can I find WordPress database credentials?

You can find the database name, username, password, and host in the wp-config.php file located in your WordPress installation directory.

3. Will repairing the WordPress database delete my website content?

The repair feature is designed to fix database issues and does not normally delete website content. However, always take a database backup before performing repairs.

4. How do I prevent database connection errors in WordPress?

Keep regular database backups, monitor server resources, maintain your database server, and ensure that database credentials and permissions remain correct.


Official Documentation

WordPress Database Repair Documentation

WordPress Support – Common WordPress Errors

Steps to reset the wordpress admin login in database

WordPress Website Protection: 7 Essential Steps

Talk to our WordPress Experts

The WordPress error establishing a database connection can prevent your website from loading, affecting website availability, user experience, and business operations. Incorrect database credentials, MySQL or MariaDB service issues, corrupted database tables, and server-side problems can cause this error.

At Pheonix Solutions, our team helps businesses troubleshoot WordPress database connection issues, resolve website errors, restore website functionality, and maintain reliable WordPress environments.

We can help you with:

  • WordPress development for WordPress website maintenance, configuration issues, plugin troubleshooting, and website recovery.
  • Security services to identify security vulnerabilities, protect database credentials, investigate suspicious activity, and strengthen WordPress security.
  • DevOps and cloud services to troubleshoot MySQL and MariaDB services, monitor server resources, manage infrastructure, and maintain database availability.
  • Software maintenance and support to investigate website errors, resolve database connectivity issues, optimize performance, and maintain website operations.
  • Backup and recovery solutions to protect WordPress databases, restore backups, and recover websites from database failures or unexpected issues.

Need help fixing the WordPress database connection error, restoring website functionality, or troubleshooting MySQL issues? Talk to our WordPress experts to discuss your requirements.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Comment

Blog newsletter

One email a month. Only what we learned.

New posts, post-mortems and the occasional strong opinion. No drip campaigns.

No spam. Unsubscribe anytime.

Work with Pheonix Solutions

Have a project in mind? Let’s build it together.

Web, mobile, cloud and DevOps, built and supported by the engineers behind these articles.

Scroll to Top