Database connection error in CloudLinux
Symptoms
When using localhost to connect to a database on CloudLinux, a connection error occurs:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)You may also see the following error in the control panel log:
aps ERROR Failed to install aps: 'PHP Warning: mysqli_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /var/www/<имя_пользователя>/data/aps_tmp/inst.0786ef4d.tmp/aps_dist/scripts/db-util.php on line 53
Unable to connect to DB: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)Solution
Make sure the following lines are present in the /etc/.my.cnf file:
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sockIf you made changes to the file, restart the MySQL service:
service mysqld restartNext, add the following line to the /etc/cagefs/cagefs.mp file if it is missing:
/var/lib/mysqlRemount CageFS for all users:
cagefsctl -M
cagefsctl --force-update