Why is my website showing a database connection error?
Summary
This guide helps you troubleshoot and resolve: Why is my website showing a database connection error?. Follow the steps below to fix the issue.
Quick Tip: Need immediate assistance? 💻 Open a Ticket
Common Causes
Quick Fix Steps
A database connection error means your website application cannot communicate with its database server. When this happens, visitors may see a blank page, an error message such as “Error establishing a database connection,” or be unable to complete actions like submitting contact forms, processing bookings, or checking out an order. This guide explains what typically causes the error and how to investigate it safely.
- Refresh your website page after a minute or two. Temporary database connection drops can resolve on their own.
- Check whether other sites on the same hosting account are loading. If multiple sites are affected, the database server itself may be down.
- Log in to your hosting control panel and verify that your database service is running.
- Confirm you have not recently changed your database password, username, or database name without updating your site’s configuration file.
- If you recently installed a plugin, extension, or theme, temporarily disable it to see if the site returns.
Detailed Instructions
Check your hosting control panel
- Log in to your hosting control panel (for example, cPanel, Plesk, or your host’s custom dashboard).
- In cPanel, navigate to Databases > MySQL Databases. In Plesk, navigate to Websites & Domains > Databases.
- Confirm that your database exists and is listed as active.
- Check whether your database is hosted locally or on an external server. In cPanel, this is shown under MySQL Databases next to the database name. If DB_HOST in your configuration file is not set to
localhost, confirm the remote hostname is correct and reachable. - If you see an option to Repair DB or Check DB, run it to identify corrupted tables.
- Review your hosting resource usage. On shared hosting plans, exceeding CPU, memory, or concurrent connection limits can cause the database to reject new connections.
Verify database user privileges
- In cPanel, navigate to Databases > MySQL Databases. In Plesk, navigate to Websites & Domains > Databases > User Management.
- Locate the database user assigned to your website’s database.
- Confirm the user has been added to the database and has the required privileges, typically All Privileges or at least SELECT, INSERT, UPDATE, and DELETE.
- If the user is not assigned, use the Add User to Database section in cPanel or the equivalent in Plesk to assign the user and grant privileges.
Verify database credentials
- Connect to your hosting account using FTP or the control panel’s File Manager.
- Locate your website’s configuration file. Common examples include:
wp-config.phpfor WordPressconfiguration.phpfor Joomlaconfig.phpor.envfor many custom PHP applications
- Download a backup copy of the file before making changes.
- Open the file and check the database settings. Look for lines similar to:
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_username' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' );- Compare these values with the database details shown in your hosting control panel. The database name, username, and password must match exactly.
- If your database is hosted on a remote server rather than locally, replace
localhostwith the remote hostname or IP address provided by your host. - If you recently reset your database password in the control panel, update the password in the configuration file and save the file.
- Refresh your website to see if the error clears.
Incorrectly editing configuration files can break your site further. Always download a backup copy before editing, and only change the database connection details unless you are confident in what you are doing.
Check error logs
- In cPanel, navigate to Metrics > Errors to view the latest error log entries. In Plesk, navigate to Websites & Domains > Log Files.
- Look for entries mentioning database connection failures, access denied errors, or timeout messages.
- Use the specific error message to narrow down whether the issue is caused by incorrect credentials, a downed database server, or a firewall blocking the connection.
Repair or optimize the database
Before repairing or optimising your database, create a full backup. Repair operations on large databases can take considerable time and may lock tables, temporarily making the database unavailable to your website.
- In your hosting control panel, open phpMyAdmin or the equivalent database management tool.
- Select your website’s database from the left-hand menu.
- Select the tables you want to check, or choose Check all.
- From the dropdown menu, choose Repair table or Optimize table.
- Wait for the operation to complete, especially if your database is large, as table locking may occur during the process.
- Reload your website and test key functions such as contact forms and checkout pages.
Investigate recent changes
- If the error started after an automated update, plugin installation, or theme change, revert that change if possible.
- For content management systems, try accessing the administrative dashboard. If the dashboard loads but the front end does not, a plugin or theme conflict is likely.
- Rename the plugin or extension folder via File Manager or FTP to disable it temporarily, then refresh your site.
- Check that your website’s scripting language version (for example, PHP version) matches the requirements of your application and installed extensions.
Advanced connectivity checks
- Advanced users can test whether the database server is reachable using
pingfollowed by the database hostname, ortelnetto the database port (typically 3306 for MySQL). - If the server does not respond, the database service may be down or a firewall may be blocking the connection.
- Contact your hosting provider if you suspect a network or server-level issue.
If you host with us, you don’t need to do this yourself — just Open a Ticket and our Brisbane team will get it sorted.
Still Having Issues?
Need more help? If the issue persists after trying these steps, please open a support ticket and our team will assist you.
💻 Open a Ticket
💻 Open a Ticket