Why Is the Website Showing a Database Connection Error?

If your website is showing a database connection error, the page usually cannot reach the database server, log in with the correct credentials, or access the database quickly enough. In a hosting environment, this can happen after a password change, a server resource issue, a corrupted database table, a wrong configuration file, or a temporary MySQL/MariaDB service problem. The good news is that most database connection errors can be diagnosed and fixed methodically.

What a database connection error means

A database connection error appears when your website’s application, such as WordPress, Joomla, Drupal, Laravel, Magento, or a custom PHP app, tries to connect to its database and fails. The database is where the site stores content, user accounts, settings, orders, and other dynamic data. If the application cannot connect, it cannot load the page properly.

Common symptoms include:

  • A blank page with a message such as Error establishing a database connection
  • Site pages loading partially or not at all
  • Admin login pages failing to load
  • Database-related messages in logs or on screen

In many cases, the issue is not with the website code itself, but with the connection between the app and the database service.

Common causes of database connection errors

Understanding the cause helps you choose the fastest fix. The most frequent reasons are listed below.

Incorrect database credentials

Your application uses a database name, database username, password, and host. If any of these values are wrong in the configuration file, the connection will fail. This often happens after:

  • A password reset in the control panel
  • A migration from another hosting environment
  • A site restore or clone
  • Manual edits to configuration files

Database service is unavailable

If MySQL or MariaDB is not running, your website cannot connect even if the credentials are correct. This may be temporary, caused by a service restart, maintenance, or high resource usage on the server.

Wrong database host

Some applications expect the database host to be localhost, while others require a specific hostname or IP address. Using the wrong host value is a common reason for connection failures, especially after moving sites between platforms.

Database user does not have permissions

The database user must have the correct privileges for the database. If permissions were removed or not assigned properly, the application may authenticate but still fail to access the database.

Corrupted database tables

Interrupted updates, server crashes, plugin conflicts, or disk issues can damage tables in the database. In that case, the connection might succeed, but the site still cannot query the data properly.

Resource limits or server load

High CPU, memory pressure, too many simultaneous connections, or hitting hosting limits can prevent the database from responding in time. This is more common on busy sites, stores, and applications with heavy traffic.

Configuration file errors

When the database settings in the site configuration file are malformed or incomplete, the application may not parse them correctly. This can happen after manual edits or failed deployments.

How to troubleshoot the issue step by step

Work through these checks in order. They cover the most common hosting and control panel scenarios.

1. Confirm whether the problem affects the whole site or only one page

Try opening multiple pages on the website, including the homepage, admin area, and a few content pages. If every page shows the same database error, the application likely cannot connect to the database at all. If only one section fails, the problem may be local to a plugin, module, or specific query.

2. Check the database credentials in the application config

For common platforms, the database credentials are usually stored in a configuration file. Check that the following values are correct:

  • Database name
  • Database username
  • Database password
  • Database host
  • Table prefix, where applicable

In WordPress, these settings are typically in wp-config.php. In other applications, they may be in .env, config.php, or another environment-specific file.

If you recently changed the database password in your hosting control panel, update the application config to match. Even a single incorrect character will cause a failure.

3. Test the database connection from the control panel

In a managed hosting or Plesk environment, use the database tools in the control panel to confirm that the database exists and the user is assigned correctly. Check whether:

  • The database is present
  • The username is linked to the database
  • The password is current
  • The database size looks normal

If your platform provides a database management interface such as phpMyAdmin, try logging in there with the same user account. If phpMyAdmin also fails, the issue is likely with the credentials or database service, not the website code.

4. Verify the database host value

Make sure the host value in your application matches the hosting platform requirements. Common values include:

  • localhost
  • 127.0.0.1
  • A named database host provided by your hosting account

Some setups use a separate internal hostname for remote database access. If you are unsure, check your hosting welcome details or the control panel database settings.

5. Check whether the database service is running

If you have access to server status tools, confirm that the MySQL or MariaDB service is active. In Plesk or similar control panels, you may also see database-related health indicators. If the service has stopped, restarting it may resolve the issue.

If you do not have server-level access, contact support and provide the time the error started. This helps identify whether the database daemon stopped, restarted, or became unavailable due to load.

6. Review error logs

Error logs often reveal whether the problem is caused by authentication failure, connection timeout, missing tables, or database corruption. Check:

  • Application error logs
  • Web server logs, such as Apache or Nginx logs
  • Database logs, where available
  • PHP error logs

Look for messages such as “access denied,” “too many connections,” “unknown database,” or “table is marked as crashed.” These clues usually point to the next fix.

7. Repair corrupted database tables

If the issue appeared after an update, crash, or failed import, a repair may be needed. Many applications and database tools provide a repair option. For example:

  • Use database repair tools in the control panel if available
  • Use phpMyAdmin to check and repair tables
  • Use the application’s built-in repair mode if supported

Only repair tables if you are confident the database is backed up. If the database is heavily damaged, a restore from a recent backup may be safer than manual repair.

8. Check for resource usage and connection limits

A database connection error can happen when the server is under pressure. Signs include slow response times, intermittent errors, or problems during peak traffic. Review:

  • CPU usage
  • Memory usage
  • Disk space
  • Number of database connections
  • PHP worker limits or process limits

If your hosting plan has reached its resource allowance, the database may fail to respond consistently. Reducing traffic spikes, disabling heavy plugins, or optimising queries can help.

9. Confirm the database exists and has not been renamed

During migrations, restores, or manual changes, the database name may change. If your website is still pointing to an old name, it will fail to connect. Double-check the exact database name in the control panel and compare it with the application config.

10. Restore from a recent backup if needed

If the problem began after a failed update, suspicious modification, or database corruption, restoring a recent backup may be the fastest reliable fix. Before restoring, confirm:

  • The backup date is before the issue started
  • You have a copy of any recent changes
  • The restore will not overwrite important work

How to fix the issue in common hosting scenarios

WordPress

For WordPress, check wp-config.php and confirm the following constants are correct:

  • DB_NAME
  • DB_USER
  • DB_PASSWORD
  • DB_HOST

If the site is showing the standard WordPress database error, also confirm that the database user still has privileges on the database. If needed, reassign the user in the control panel and test again.

Plesk environments

In Plesk, verify the database under the subscription or domain settings. Check that the correct database user is assigned and that the password matches the value in the application configuration. Use the database administration tools to confirm the database responds normally.

If the application was migrated into Plesk, database host values may need updating if the old hostname is still referenced in the site config.

Custom PHP applications

Custom applications often store database details in a config file or environment file. Confirm that the file is readable by the web server and contains valid values. Check also for extra spaces, missing quotes, incorrect encoding, or stale environment variables from deployment.

Magento, Laravel, Joomla, Drupal and similar platforms

These platforms typically use config files or environment-based database settings. After a deployment or restore, verify that:

  • The database name matches the active database
  • The user has the correct permissions
  • The host value is compatible with your hosting setup
  • Any cached config has been cleared

Preventing future database connection errors

While not every error can be avoided, a few good practices reduce the risk significantly.

  • Keep a record of database names, users, and hosts used by each site
  • Use strong passwords, but update configuration files immediately after changing them
  • Monitor disk space and resource usage regularly
  • Apply updates during low-traffic periods
  • Take regular backups of both files and databases
  • Test restores occasionally so you know backups are usable
  • Avoid unnecessary changes directly on live configuration files

For busy websites, caching and database optimisation can also reduce the risk of timeouts and overloaded connections.

When to contact support

If you have checked the credentials, host value, permissions, and logs, but the error continues, it is time to contact support. Send as much detail as possible so the issue can be investigated faster:

  • The exact error message shown on the website
  • The time the issue started
  • Any recent changes, updates, or migrations
  • The affected domain or application
  • Relevant error log entries
  • Whether the issue affects the admin area, frontend, or both

If the problem is caused by a service outage, database daemon issue, or server-level resource pressure, support can check the platform side and advise on the next step.

FAQ

Why does my website suddenly show a database connection error?

This usually means something changed on the database side, the application side, or both. Common triggers include a password change, server restart, failed update, corrupted table, or resource issue.

Can a plugin or extension cause a database connection error?

Yes. A faulty plugin, module, or extension can trigger heavy queries, corrupt data, or change configuration unexpectedly. If the error started after installing or updating an add-on, disable it if possible and test again.

Is this the same as a website down error?

Not exactly. A database connection error is a specific type of website failure caused by the app not reaching its database. The site may still be online, but it cannot render correctly without the data layer.

Will clearing cache fix the problem?

Clearing cache may help if the issue is caused by stale configuration or a temporary bad page cache, but it will not fix incorrect credentials, service outages, or database corruption.

How do I know if the database username has permission to the database?

Check the database management section in your control panel. The user should be assigned to the database with the required privileges. If in doubt, remove the user from the database and add it again with full access, then test the site.

What if the error only appears sometimes?

Intermittent errors often point to overload, connection limits, or a resource bottleneck. Review usage graphs, logs, and peak traffic periods. Intermittent failures can also happen if the database service is restarting or unstable.

Conclusion

A database connection error usually means the website cannot reach MySQL or MariaDB because of incorrect credentials, a wrong host, missing permissions, service downtime, corruption, or server resource limits. Start by checking the configuration file, then verify the database in your control panel, review logs, and confirm the database service is running. If the problem follows a recent change, restore or correct that change first. For hosting platforms, this approach resolves most cases quickly and safely.

  • 0 Users Found This Useful
Was this answer helpful?