CLYTRIX
All systems operational New York StatusSupportBlog
Plesk

How to Resolve Database Connection Errors in Plesk Panels

How to Resolve Database Connection Errors in Plesk Panels

Database connectivity is essential for dynamic CMS platforms, customer panels, and web applications. In Plesk server environments, MySQL or MariaDB serves as the default database management engine. However, database crashes, incorrect user credentials, or local socket file errors can cause applications to return "Error Establishing a Database Connection" or "SQLSTATE[HY000] [2002] Connection refused" errors. When these errors occur, database-driven sites go offline immediately.

For systems administrators, resolving database errors requires isolating the issue to credential mismatches, server resource exhaustion, or service daemon crashes. In this guide, we will analyze Plesk's database architecture, check service logs, and walk through the SSH commands to debug database connections and repair MySQL/MariaDB configurations.

1. Common Causes of Database Connection Failures

In Plesk, database connection failures are typically due to one of three main issues:

  • Service Outages: The MySQL or MariaDB daemon has stopped running due to server memory exhaustion or configuration errors.
  • Socket File Mismatches: The web server tries to connect to the database via a local socket file (e.g., /var/lib/mysql/mysql.sock), but the socket file has been deleted or moved.
  • Authentication Failures: Mismatched database names, usernames, or passwords in your web application's configuration files (such as wp-config.php).

2. Step-by-Step Database Diagnostics via SSH

To troubleshoot database connection issues in Plesk, log into your server via SSH as the root user. Run these diagnostic commands to verify service status, repair tables, and check local sockets.

Step 2.1: Verify MySQL/MariaDB Daemon Status

Verify if the database service is running on your server. Run the command appropriate for your operating system:

systemctl status mariadb     # On CentOS/RHEL/AlmaLinux
systemctl status mysql       # On Debian/Ubuntu

If the service is inactive, attempt to restart it and check the startup output for errors:

systemctl restart mariadb    # Or mysql

Step 2.2: Verify Server Disk Space and Memory

Database services can crash if the server runs out of disk space or RAM. Check disk usage and memory allocations by running:

df -h                        # Verify disk space
free -m                      # Verify free RAM

If the server disk space is 100% full, the database service cannot write temporary files or logs, causing it to shut down. Free up disk space by removing log files or old backups before restarting the service.

Step 2.3: Locate and Verify the MySQL Socket File

If the database service is active but local connections fail, the issue may be due to a socket file mismatch. Inspect your MySQL configuration file to find the defined socket path:

grep -i "socket" /etc/my.cnf

Verify that the socket file exists at the defined path (e.g., /var/lib/mysql/mysql.sock). If it is missing, restart the service to recreate the socket file, or verify the directory permissions:

ls -la /var/lib/mysql/mysql.sock

Step 2.4: Test Database Authentication from CLI

Verify database credentials by testing the connection using the MySQL client command-line tool, entering your database username and password:

mysql -u db_user_name -p -h localhost db_name

If this connection is successful, your server database is active and accepting connections, indicating that the issue is likely due to incorrect credential settings in your application's configuration file.

3. Plesk Database Troubleshooting Summary

Database Error Common Root Cause Recommended Action
Connection Refused (Port 3306) Database daemon is offline or port is closed Start service; verify port 3306 status in firewall rules
Can't connect to local MySQL server through socket Missing or inaccessible mysql.sock file Restart service; verify permissions on /var/lib/mysql/
Access denied for user Mismatched database credentials in config files Verify and update database credentials in application configuration

Frequently Asked Questions (FAQ)

How does Plesk isolate database users?

Plesk assigns specific database users to separate database instances, restricting access using MySQL's privileges system. This prevents one user from accessing or modifying database tables belonging to other hosting accounts.

Where are MySQL logs located in Plesk?

Database log locations depend on the operating system. In CentOS/RHEL/AlmaLinux, logs are usually written to standard paths like /var/log/mariadb/mariadb.log or /var/log/mysqld.log. In Debian/Ubuntu, check /var/log/mysql/error.log.

Can a full disk cause database table corruption?

Yes. If the server storage fills up completely during a write operation, the database service cannot finish writing the transaction files to disk. This can result in corrupted tables or broken index files when the service restarts.

Ready to Put These Guides Into Practice?

Deploy in under 60 seconds. Plans from $0.69/mo.