Troubleshooting Common Database Connection Errors in Plesk

Database connection errors can be frustrating, especially when running websites and applications on Plesk. These errors usually prevent a site from communicating with its database, leading to downtime or service interruptions. In this blog, we’ll explore the most common database connection errors you may encounter in Plesk and how to troubleshoot them effectively.

Common Database Connection Errors

Database Connection Errors

1. Database Does Not Exist

Error Message:

  • Unknown database '<database_name>'

Causes:

  • The database may not have been created.
  • Database name might be incorrect in configuration files.

Solution:

  • Double-check the database name in your website’s configuration file (such as wp-config.php for WordPress).
  • Verify that the database exists in Plesk by navigating to Websites & Domains > Databases.

2. Invalid Database Credentials

Error Message:

  • Access denied for user 'username'@'localhost' (using password: YES)

Causes:

  • Incorrect database username or password.
  • Changes to database credentials that haven’t been updated in the application.

Solution:

  • Verify the correct username and password in the application’s configuration file.
  • You can reset the database user’s password in Plesk under Websites & Domains > Databases > User Management.

3. Too Many Connections

Error Message:

  • Error: Too many connections

Causes:

  • The database server has hit the maximum number of concurrent connections allowed.

Solution:

  • Increase the connection limit by modifying the max_connections parameter in the MySQL configuration file (my.cnf).
  • Alternatively, close idle connections or restart the database server to free up connections.

4. Database Server is Down

Error Message:

  • Cannot connect to the MySQL database

Causes:

  • MySQL/MariaDB service is not running.
  • The server may have crashed or failed to start.

Solution:

  • Restart the MySQL service from Plesk’s control panel: Tools & Settings > Services Management > MySQL Server.
  • Check for any error logs in /var/log/mysql to identify why the service might have failed.

5. Corrupted Database Tables

Error Message:

  • Table './<database_name>/<table_name>' is marked as crashed and should be repaired

Causes:

  • Database tables might become corrupted due to server crashes or file system issues.

Solution:

  • Repair the table from Plesk by going to Websites & Domains > Databases > Repair.
  • Alternatively, you can use the mysqlcheck command in the terminal to repair corrupt tables.

6. Firewall Blocking Access

Error Message:

  • Unable to establish a database connection

Causes:

  • The firewall may be blocking communication to the database server, especially if connecting from an external host.

Solution:

  • Ensure that the firewall allows traffic on the MySQL port (default: 3306). You can check firewall settings in Plesk under Tools & Settings > Firewall.

7. Incorrect Hostname in Database Configuration

Error Message:

  • Could not connect: Host '<hostname>' is not allowed to connect to this MySQL server

Causes:

  • The hostname configured in the database connection file is incorrect.

Solution:

  • Ensure the hostname matches the correct value, whether localhost for local connections or an external server address for remote access.

8. DNS Resolution Issues

Error Message:

  • Unable to resolve host '<hostname>'

Causes:

  • DNS resolution issues between the server and the database.

Solution:

  • Use IP addresses instead of hostnames in database connection settings to avoid DNS problems.
  • Ensure that your DNS is properly configured and resolving correctly.

9. Outdated PHP/MySQL Versions

Error Message:

  • Varies depending on compatibility issues.

Causes:

  • Incompatibility between PHP and MySQL versions.

Solution:

  • Update PHP and MySQL/MariaDB to compatible versions via Plesk’s update manager.
  • Check compatibility requirements for your application.

10. Disk Space Exhausted

Error Message:

  • Unable to write to MySQL database

Causes:

  • The server has run out of disk space, preventing new data from being written.

Solution:

  • Free up space on your server by deleting unnecessary files, or increase your storage capacity.

Conclusion

Database connection errors in Plesk can stem from a variety of issues ranging from incorrect credentials to server outages. By understanding the root causes and using Plesk’s built-in tools, you can quickly diagnose and fix these errors to keep your website running smoothly.