Website error establishing a database connection
Summary
This guide helps you troubleshoot and resolve: Website error establishing a database connection. Follow the steps below to fix the issue.
Common Causes
An "Error establishing a database connection" means your website's application cannot communicate with its database. This typically occurs when login credentials are incorrect, the database server is unresponsive, or the database itself has become corrupted. Because your website relies on this connection to display content, process orders, and load administrative dashboards, this error usually results in the entire site becoming inaccessible.
Remember — 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.
Quick Fix Steps
- Verify your database credentials in your website's configuration file.
- Check that your database server is running and responding to requests.
- Repair the database using your hosting control panel tools.
- Confirm that your database user has the correct permissions assigned.
- Restart the database service if you have server-level access.
Detailed Instructions
Verify Database Credentials
- Access your website files via FTP or your hosting control panel's file manager.
- Locate your website's configuration file. Common paths include:
wp-config.phpfor WordPress installationsconfiguration.phpfor Joomlaconfig.phpfor OpenCart or custom PHP applications
- Open the file and look for the database connection settings. You will typically find entries such as:
DB_NAME— the name of your databaseDB_USER— the database usernameDB_PASSWORD— the database passwordDB_HOST— usuallylocalhost, though some providers use a specific hostname
- Log in to your hosting control panel and navigate to the Databases or MySQL Databases section.
- Confirm that the database name, username, and host match exactly what is listed in your configuration file.
- If the password does not match, reset the database user password in your control panel and update the configuration file with the new value.
- Save the configuration file and refresh your website in a browser.
Always download a backup copy of your configuration file before making changes. This allows you to restore the original settings if a typo causes further issues.
Check Database Server Status
- Log in to your hosting control panel.
- Open phpMyAdmin or the equivalent database management tool.
- Attempt to log in using your database username and password.
- If you cannot log in, the database server may be down or your credentials may be incorrect.
- If you can log in but cannot see your database, the database may have been deleted or the user may lack permission to access it.
- If you are on a VPS or dedicated server, use the command line to check the database service status. For example, on many Linux systems you can run
systemctl status mysqlorsystemctl status mariadb.
Do not restart database services on a production server unless you are comfortable with server administration. An improper restart can cause data corruption or extended downtime.
Repair the Database
- Log in to your hosting control panel and open phpMyAdmin.
- Select your website's database from the left-hand menu.
- Select all tables, or select the tables that are reporting errors.
- From the With selected: dropdown menu, choose Repair table.
- Alternatively, if you use WordPress, you can enable automatic repair by adding the following line to your
wp-config.phpfile:define('WP_ALLOW_REPAIR', true); - Visit
yourdomain.com/wp-admin/maint/repair.phpin your browser and click Repair Database. - Once the repair is complete, remove the repair line from your
wp-config.phpfile to prevent unauthorised access to the repair script.
Verify Database User Permissions
- In your hosting control panel, open the MySQL Databases section.
- Locate the user assigned to your database.
- Click Add User to Database or Manage Privileges.
- Ensure the user has all necessary privileges, including SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, and INDEX.
- Save the changes and test your website again.
Troubleshooting
Error Started After a Plugin or Extension Update
- Access your site files via FTP or file manager.
- Navigate to your plugins or extensions directory. For WordPress, this is typically
wp-content/plugins/. - Rename the folder of the recently updated plugin to something like
plugin-name-disabled. - Refresh your website to see if the error clears.
- If the site loads, the plugin is incompatible with your current database version or configuration. Contact the plugin developer or restore a backup from before the update.
Error Started After a Script Version Change
- Confirm that your website application version is compatible with your database server version.
- Some newer applications require MySQL 5.7 or 8.0, while older scripts may only work with MySQL 5.6 or earlier.
- Check your hosting control panel for the database server version under Server Information or Database Settings.
- If there is a version mismatch, you may need to update your website application or contact your hosting provider about database server options.
Database Connection Drops Intermittently
- Check your website's error logs for messages such as "Too many connections" or "MySQL server has gone away."
- If you see "Too many connections," your site may be exceeding the database connection limit imposed by your hosting plan.
- Optimise your website's database queries or upgrade your hosting plan to allow more concurrent connections.
- Ensure that persistent connections are not enabled in your application configuration unless specifically required.
If you recently migrated your website to a new host, ensure that you updated the DB_HOST value in your configuration file. The hostname often changes between providers, even if the database name and username remain the same.
Remember — 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?
💻 Open a Ticket