Introducing ZYNOO General Purpose & CPU Optimized Servers   Learn More >

How to Fix Error Establishing a Database Connection in WordPress

The “error establishing a database connection” message in WordPress means your website cannot connect to its MySQL or MariaDB database. Common causes include incorrect database credentials, an unavailable database server, or hosting resource limits.

The first thing to check is your database configuration in wp-config.php. If those settings are correct, you’ll need to investigate the database server and its availability.

This guide explains how to identify the cause and restore your website safely.

What Causes the WordPress Database Connection Error?

WordPress relies on a database to store posts, pages, settings, and user information. When that connection fails, WordPress cannot retrieve the information needed to load your website.

The most common causes are:

  • Incorrect database name, username, or password.
  • Wrong database hostname.
  • MySQL or MariaDB service downtime.
  • Missing database user permissions.
  • Database connection limits or insufficient server resources.
  • Incorrect settings following a website migration.

Before troubleshooting, back up your website files and database if possible, especially before making configuration changes or attempting repairs.

1. Check Your Database Credentials in wp-config.php

Incorrect database credentials are one of the most common reasons WordPress cannot connect to its database.

The wp-config.php file contains the information WordPress uses to establish that connection.

WordPress wp-config.php database configuration showing DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST settings

How to locate wp-config.php

  1. Log in to your hosting control panel.
  2. Open File Manager or connect through SFTP.
  3. Navigate to your WordPress installation directory, commonly public_html.
  4. Find the wp-config.php file.
  5. Download a backup copy before editing it.

Look for these four settings:

define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_user' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' );

These are examples, not values you should copy into your configuration.

Compare them with the database information in your hosting control panel.

If the username, database name, or password is incorrect, update the relevant setting.

Remember that your database credentials are different from your WordPress administrator login.

2. Verify Your Database Host

Even with the correct credentials, WordPress cannot connect if the database hostname is wrong.

Many hosting environments use:

define( 'DB_HOST', 'localhost' );

However, some providers use a separate hostname, IP address, or custom port.

Don’t randomly change localhost to 127.0.0.1. Depending on the server configuration, these values can use different connection methods.

Confirm the correct database host through your hosting control panel or provider.

If the error establishing a database connection appeared immediately after migrating your website, checking the new database hostname is especially important.

3. Check Whether Your Database Server Is Running

If the credentials and database host are correct, the next step is checking the database service.

On shared hosting

Open your hosting control panel and try accessing the database through phpMyAdmin, if available.

If phpMyAdmin also reports connection problems, contact your hosting provider to check the database service.

Keep in mind that phpMyAdmin working doesn’t necessarily mean the database username configured in WordPress has the correct permissions.

On a VPS or dedicated server

If you manage your own Linux server, connect through SSH.

To check MariaDB:

sudo systemctl status mariadb

To check MySQL:

sudo systemctl status mysql

Service names can vary by operating system and installation.

If the database service is stopped, examine its logs and available resources before restarting it.

A stopped database service can prevent every website depending on that database from connecting.

4. Verify Database User Permissions

WordPress needs a database user with sufficient permissions to access the configured database.

If you’ve migrated a website or restored a backup, the database user might not be associated with the correct database.

In cPanel, open the database management area and check that:

  • The database exists.
  • The configured database user exists.
  • The user is assigned to the correct database.
  • The account has the privileges WordPress requires.

Avoid changing permissions blindly. Ask your hosting provider for assistance if you’re unsure.

5. Check for Database Corruption

Database corruption is less common than incorrect credentials or server availability problems.

However, if WordPress reports damaged database tables or database repair is specifically indicated, you may need to investigate further.

WordPress includes a database repair feature.

First, create a reliable backup. Then temporarily add this line to wp-config.php:

define( 'WP_ALLOW_REPAIR', true );

Visit:

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

Follow the available repair instructions.

Important: This page doesn’t require an authenticated WordPress session while the repair feature is enabled. Remove the WP_ALLOW_REPAIR line immediately afterward.

Database repair won’t fix incorrect credentials, an unavailable database server, or every form of database corruption. Use it only when appropriate.

6. Check Server Resources and Database Limits

Does the error appear during busy periods but disappear when you refresh the page?

This may indicate database connection limits, resource exhaustion, or temporary server problems.

Ask your hosting provider to investigate:

  • CPU and memory usage.
  • Database connection limits.
  • Available disk space.
  • Database service crashes or restarts.
  • Relevant PHP and database error logs.

On a self-managed server, review the same information directly.

Don’t assume that upgrading your hosting plan will solve the problem. Identify the actual cause first.

If the error establishing a database connection occurs intermittently, note when it happens and whether it coincides with high traffic or scheduled tasks.

7. Review Recent WordPress or Hosting Changes

If your website recently stopped working, check what changed just before the problem appeared.

Website migration: Confirm the database was imported and that wp-config.php contains the new credentials and hostname.

Password changes: Make sure WordPress is using the current database password.

Hosting changes: Verify that the database service, hostname, and user permissions are configured correctly.

Plugin or application changes: Investigate whether excessive database queries or connections are affecting availability.

What If the Error Still Appears?

If none of the previous steps resolves the problem, contact your hosting provider.

Provide the approximate time the issue started, whether it occurs continuously or intermittently, and any recent changes to your website.

Explain which troubleshooting steps you’ve already completed. Never send database passwords through ordinary support messages.

How to Prevent Future Database Connection Problems

Not every outage can be prevented, but good maintenance can reduce avoidable failures.

  • Maintain regular website and database backups.
  • Keep WordPress, themes, and plugins updated.
  • Monitor database connections and resource usage.
  • Maintain sufficient server storage.
  • Test website migrations before switching production traffic.
  • Keep database credentials secure.
  • Monitor database service health on self-managed servers.

These measures help reduce the likelihood of unexpected database availability problems.

Frequently Asked Questions

Does this error mean my WordPress database is deleted?

No. The error indicates that WordPress cannot establish a connection. Your database and its contents may still be intact.

Can a WordPress plugin cause a database connection error?

Yes, indirectly. A poorly optimized plugin may generate excessive database queries or connections, contributing to resource exhaustion.

Can I fix the error without accessing wp-admin?

Yes. Most troubleshooting takes place through your hosting control panel, File Manager, SFTP, or SSH.

Should I reinstall WordPress to fix this error?

Usually not. Reinstalling WordPress won’t correct database credentials or restore a stopped database service, and unnecessary changes can introduce additional problems.

Conclusion

Fixing the error establishing a database connection in WordPress starts with verifying your database credentials, hostname, and server availability.

If those settings are correct, investigate database permissions, resource limits, and recent configuration changes before attempting repairs.

Work through the checks systematically, and contact your hosting provider if the database service or server infrastructure requires investigation.

Table of Content

Moving to a new server requires careful planning to avoid downtime, data loss, and configuration

Choosing a dedicated server 10Gbps plan requires more than comparing network speeds. The right server

A WordPress staging site is a private copy of your live website where you can

Build your next project with ZYNOO

From your first website to demanding applications, choose the resources and control you need.

Shared Hosting

Start your blog or business website with cPanel, LiteSpeed and CloudLinux.

VPS Hosting

Grow your websites and applications with NVMe storage, KVM virtualization and full root access.

Dedicated Servers

Power demanding projects with your own physical server, dedicated resources and control over your environment.

Scroll to Top