skip to Main Content

How to Fix WordPress Database Connection Error (2026)

Seeing the “Error Establishing a Database Connection” message on your WordPress website can be frustrating. Instead of displaying your homepage, WordPress shows an error because it cannot establish a connection to the database it needs to load your website.

This problem can occur after changing database credentials, migrating a website, experiencing a database server issue, or exhausting available hosting resources. In some cases, the cause is a simple configuration mistake; in others, it requires investigation by your hosting provider.

In this guide, you will learn how to identify the cause and fix the WordPress database connection error step by step.

What Does “Error Establishing a Database Connection” Mean?

WordPress uses a database, typically MySQL or MariaDB, to store important website information, including:

  • Posts, pages, and comments
  • User accounts and permissions
  • Website settings
  • Plugin and theme configuration
  • Other content managed by WordPress

When someone visits your website, WordPress needs to connect to its database to retrieve the information required to generate the page.

If that connection fails, WordPress cannot retrieve the necessary data and may display the database connection error instead.

The error does not automatically mean your database has been deleted or corrupted. It can also indicate incorrect login details, a database service problem, a connection limit, or another server-side issue.

1. Check Whether Your Hosting Server Is Experiencing an Issue

Before changing WordPress configuration files, check whether the problem originates from your hosting environment.

A database service may be temporarily unavailable because of maintenance, a service failure, excessive resource usage, or another server-side problem.

What to check

  1. Open your hosting provider’s status page, if available.
  2. Check whether other websites hosted on the same account are experiencing similar problems.
  3. Look for recent hosting changes, maintenance notifications, or resource-limit warnings.
  4. If you have access to cPanel, check whether the hosting account is approaching its resource limits.

If multiple websites using the same database server fail at the same time, a shared server-side issue becomes more likely.

However, one affected website does not rule out a server problem. If you cannot identify the cause, ask your hosting provider to check the MySQL or MariaDB service, database connection limits, and relevant server logs.

2. Verify Your WordPress Database Credentials

Incorrect database credentials are one of the first things to investigate, especially if the error appeared after a migration, hosting change, or manual configuration update.

WordPress stores its database connection settings in the wp-config.php file located in the WordPress installation directory.

Step 1: Open the WordPress installation directory

Log in to cPanel and open File Manager.

Navigate to the directory containing your WordPress installation. For a primary domain, this is often public_html, although the location can differ depending on your hosting setup.

Find the wp-config.php file and open it for editing.

Before making changes, download a backup of the file. Never share its contents publicly because it contains sensitive database configuration information.

Step 2: Find the database configuration

Look for these settings:

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

These are example values. Your actual settings may be different.

Each setting has a specific purpose:

  • DB_NAME: The name of the WordPress database.
  • DB_USER: The database user assigned to WordPress.
  • DB_PASSWORD: The password for that database user.
  • DB_HOST: The database hostname or connection address provided by your hosting provider.

Step 3: Compare the settings with your hosting account

Check the database name and username in cPanel’s MySQL Databases interface, if your hosting environment provides it.

Confirm that:

  • The database exists.
  • The database username is correct.
  • The password matches the current database user’s password.
  • The database user has the required privileges on the database.
  • The DB_HOST value matches the setting supplied by your hosting provider.

Some hosting environments require a specific database hostname rather than localhost. Do not change this value unless you have confirmed the correct setting.

If you recently changed the database password, update DB_PASSWORD to match the new password.

Save the file and test the website again.

Important: Do not post your real wp-config.php contents in public forums or support discussions. Redact passwords, usernames, database names, authentication keys, and other sensitive values before sharing configuration details.

3. Confirm That the Database Exists and the User Has Access

Even when the credentials look correct, WordPress may fail to connect if the database has been removed, renamed, or is no longer accessible to its assigned user.

Check the database in cPanel

  1. Log in to cPanel.
  2. Open MySQL Databases, if available.
  3. Locate the database used by WordPress.
  4. Confirm that the database user is assigned to it.
  5. Verify that the user has the necessary privileges.

On many cPanel installations, database names and usernames include an account prefix. For example, a database might appear as account_wpdb rather than simply wpdb.

Use the exact names shown in your hosting account.

What if the database is missing?

Do not immediately create a new empty database with the same name and assume the problem is fixed. WordPress needs its existing content and tables.

If the database is missing or inaccessible, contact your hosting provider to investigate whether it was renamed, removed, affected by a service problem, or can be restored from a backup.

Before attempting a restoration, confirm that a suitable backup exists and understand that restoring an older copy may overwrite newer data.

4. Check Whether MySQL or MariaDB Is Running

WordPress depends on a working database service. Even correct credentials cannot establish a connection if the database server is unavailable or refusing connections.

What you can check

If you use shared hosting, contact your hosting provider and ask them to verify:

  • Whether the MySQL or MariaDB service is running.
  • Whether the database server is accepting connections.
  • Whether connection limits have been reached.
  • Whether database-related errors appear in the server logs.

If you administer a VPS or dedicated server with appropriate permissions, you can check the service status from the command line.

For example, on a Linux system using systemd:

sudo systemctl status mariadb

On systems where the service is named mysql, use:

sudo systemctl status mysql

The correct service name depends on your operating system and installation.

If the service is stopped, investigate the reason before attempting to restart it. Database crashes, disk exhaustion, configuration problems, and resource shortages may cause the service to stop or fail again.

On a production server, avoid repeatedly restarting the database without checking the logs. If you are not responsible for server administration, ask your hosting provider to investigate instead.

5. Test Whether the Database Is Accessible

If the database server is running, the next step is to determine whether the database itself is accessible.

Where your hosting environment supports phpMyAdmin, open it from cPanel and check whether you can access the expected database and view its tables.

If phpMyAdmin cannot connect to the database server, the issue may be related to database availability, server configuration, or access restrictions.

If phpMyAdmin works but WordPress still shows the error, focus on the WordPress database settings, the database user’s privileges, and the application’s connection configuration.

For administrators with command-line database access, a connection test can also help isolate the problem:

mysql -u DATABASE_USER -p -h DATABASE_HOST DATABASE_NAME

Replace the example values with your actual database username, hostname, and database name. The command prompts for the password rather than requiring it to be written directly into the command.

Do not assume that a successful phpMyAdmin login proves that WordPress’s credentials are correct. phpMyAdmin may use a different authentication method or account.

6. Check for Database Connection Limits and Resource Problems

A database server can be running normally but still refuse new connections when its configured connection limit is reached or the hosting account is experiencing resource pressure.

This can happen when a website receives a sudden increase in traffic, a plugin generates excessive database requests, or an application has inefficient queries.

Possible warning signs

  • The website works intermittently.
  • The database error appears during traffic spikes.
  • The problem affects several pages or applications at once.
  • Hosting resource usage is unusually high.
  • Server logs contain connection-limit or resource-related errors.

How to investigate

If you use shared hosting, ask your hosting provider to review database connection errors, account resource usage, and any applicable database or process limits.

On a server you administer, review the MySQL or MariaDB logs and relevant performance metrics before changing connection limits.

Increasing a database connection limit without understanding available memory and workload can make the problem worse. The goal is to identify why the connections are being exhausted, not simply to allow more of them.

If a plugin or custom application is generating excessive queries, correcting the underlying workload may be more effective than increasing server limits.

7. Repair the WordPress Database if Necessary

Database corruption is another possible cause of website failures. However, a database connection error alone does not prove that the database is corrupted.

First, confirm that the database server is reachable and that the credentials and permissions are correct. Only investigate database repair when there is evidence that the database or its tables may be damaged.

Back up the database first

Before attempting a repair, create a backup of the database if possible. If the database cannot be accessed, ask your hosting provider or server administrator to help preserve the available data before making changes.

Use WordPress’s database repair feature carefully

WordPress includes a database repair mechanism that can be enabled temporarily through wp-config.php.

Add this line to the file:

define( 'WP_ALLOW_REPAIR', true );

Then visit:

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

Replace example.com with your own domain.

Follow the on-screen instructions if the repair page is accessible.

Security warning: The repair page can be accessed without normal authentication while this feature is enabled. Enable it only when needed, use it briefly, and remove the WP_ALLOW_REPAIR line from wp-config.php immediately after completing the task.

The repair tool does not fix every type of database problem, and repairing tables is not a substitute for investigating a failed database service or incorrect credentials.

If the repair page cannot connect to the database, return to the connection diagnostics rather than assuming that database corruption is the cause.

8. Investigate Recent Plugin, Theme, or Website Changes

Plugins and themes can contribute to database-related problems by generating excessive queries, triggering application errors, or interacting with a failing database connection.

However, a plugin is not automatically responsible simply because the error appears on a WordPress website.

Think about what changed immediately before the error started.

For example:

  • Was a new plugin installed or updated?
  • Was a theme changed?
  • Was WordPress migrated to another server?
  • Were database credentials or configuration files edited?
  • Did the website experience an unexpected traffic increase?

If you suspect a plugin or theme, investigate the relevant PHP error logs and application changes.

On a staging copy or a site where you can safely test changes, disable suspected plugins and check whether the problem disappears. If you cannot access the WordPress dashboard, you may need to use an alternative method appropriate to your hosting environment.

Do not rename the entire plugins directory on a busy production website without considering the effect on its functionality.

If a recent deployment or update introduced the problem, consider rolling back the specific change using a verified backup or your normal deployment process.

9. Check Disk Space and Hosting Resource Usage

A server that runs out of available disk space may experience database failures, write errors, or other service problems.

Disk exhaustion is not the most common explanation for every WordPress database connection error, but it is worth investigating when the issue coincides with full storage, large log files, failed backups, or database service problems.

Check the following:

  • Available disk space in your hosting account.
  • Inode usage, if your hosting provider applies an inode limit.
  • Database storage and error logs.
  • CPU and memory usage.
  • Hosting resource-limit notifications.

If your account is at its storage limit, remove only files you have verified are unnecessary or expand the available storage as appropriate. Do not delete database files or unfamiliar system files to free space.

If the database server is affected, a hosting administrator may need to inspect the server’s filesystem and database logs.

10. Contact Your Hosting Provider if the Error Persists

If you have verified your database credentials, confirmed that the database exists, and still cannot establish a connection, the issue may require server-level investigation.

Your hosting provider can inspect information that may not be available through your hosting control panel.

Ask the support team to check:

  • MySQL or MariaDB service status.
  • Database authentication and permission errors.
  • Database connection limits.
  • Account resource restrictions.
  • Disk space and server-side storage issues.
  • Relevant database and PHP error logs.

Include the time the problem started, any recent configuration changes, and whether the website fails continuously or intermittently.

Avoid sending your database password or full wp-config.php file in an ordinary support message.

If you need reliable hosting for a WordPress website, explore AmarHost Premium Hosting, Budget Hosting, or Student Hosting. Choose a plan based on your website’s resource requirements and the support you need.

How to Prevent WordPress Database Connection Errors

Although not every database failure can be prevented, a few good practices can reduce the risk and make troubleshooting easier.

Maintain regular backups. Keep database and website-file backups, and periodically verify that they can be restored.

Protect database credentials. Keep wp-config.php secure and update its settings carefully when credentials change.

Monitor hosting resources. Watch disk space, memory, CPU, and other resource limits that apply to your hosting account.

Keep WordPress components maintained. Update WordPress, plugins, and themes responsibly, preferably after taking a backup and testing significant changes where possible.

Investigate recurring errors. If the same problem happens repeatedly, review the logs and connection patterns instead of treating each occurrence as an isolated incident.

Plan migrations carefully. Verify database credentials, database contents, file configuration, and application connectivity before directing production traffic to a new server.

Final Thoughts

The WordPress “Error Establishing a Database Connection” message can result from several different problems, including incorrect credentials, missing database access, an unavailable database service, exhausted connections, resource limitations, or database corruption.

Start with the simplest checks: verify wp-config.php, confirm that the database exists and the user has access, and determine whether the database service is available. Then investigate connection limits, server resources, and possible database damage if the initial checks do not resolve the issue.

Avoid making multiple changes at once. Test each change, preserve a backup before risky operations, and contact your hosting provider when the problem requires access to server logs or database services.

Latest Articles
October 9, 2026

Resolving the ‘Can NOT Find LSCWP Path for Object Cache Initialization’ Error on Your WordPress Site

Seeing the message "Can NOT find LSCWP path for object cache initialization in /home/cP_username/html/wp-content/object-cache.php" on your WordPress dashboard can be…

September 15, 2025

How to Add Profile Picture in Webmail Using Gravatar

Having a professional email address is important, but adding a profile picture makes it even more personal and trustworthy. In…

Subscribe To Our Newsletter

Don't get left out of the loop, make sure you subscribe to our newsletter below so you can be notified of our latest insights, tips, tutorials, sales and more!

Discussion
Back To Top