Are you facing 'ERROR: PleskDBException: Unable to connect to database'?
This guide will help you.
This Plesk error can occur due to various reasons that include InnoDB engine corruption, disk space full, data directory not completely restored or recovered, and so on.
In this context, we shall look into how to fix this Plesk error.
How to fix error: pleskdbexception: unable to connect to database ?
Recently, one of our customers approached us telling us that when he tried to access the Plesk control panel, the following error appears:
"ERROR: PleskDBException: Unable to connect to database: mysql_connect(): No such file or directory /var/run/mysqld/mysqld.sock (Error code: 2002). Please check that the database server is started and accessible. (Abstract.php:69)"
MySQL works fine and even the web applications are running without any problems.
Now let's take a look at how our Support Experts resolve this error.
We went through the MySQL logs by running the below command:
$ grep mysql /var/log/syslog | tail -50
As a result, we found the below log entries:
Mar 21 00:16:58 h2600744 /etc/init.d/mysql: 0 processes alive and ‘/usr/bin/mysqladmin –defaults-file=/etc/mysql/debian.cnf ping’ resulted in Mar 21 00:16:58 h2600744 /etc/init.d/mysql: #007/usr/bin/mysqladmin: connect to server at ‘localhost’ failed
Mar 21 00:16:58 h2600744 /etc/init.d/mysql: error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ Aug 12 00:16:58 h2600744 /etc/init.d/mysql: Check that mysqld is running and that the socket: ‘/var/run/mysqld/mysqld.sock’ exists!
Here are the steps we follow to resolve this error.
1. First, we rename the file /etc/init/mysql.conf to /etc/init/mysql.conf.off. For that, we run the below command:
# mv /etc/init/mysql.conf /etc/init/mysql.conf.off
2. Next, we start the MySQL service. For that, we run the following commands:
# sudo service mysql stop
# sudo service mysql start
Also, we can also perform "plesk repair db -v".
i. The socket will not exist if mysqld refuses to start. So we check if the data directory is completely restored/recovered. If not, we will need to recover it.
ii. Also, we delete files that are not needed so that we can free up some disk space.
We can check the disk space using df and du commands.
# df -h
The du command displays disk usage. Or else, we can run the below command.
# du -h
Moreover, we can add the skip-grant-tables option into /etc/mysql/my.cnf after that we should be able to start the database server.