Enabling CloudLinux CageFS generates “error establishing a database connection” on websites

Enabling CloudLinux CageFS generates “error establishing a database connection” on websites

Error

You will see sites showing database connection error even when database login details configured are correct.

Cause

This happens when mysql data directory “/var/lib/mysql” is not mounted in cagefs.

[root@servermanagementplus.com ~]# grep "/var/lib/mysql" /etc/cagefs/cagefs.mp
[root@servermanagementplus.com ~]#

As you can see there is no “/var/lib/mysql” folder entry in the cagefs.mp file

Resolution

Add the lines “/var/lib/mysql” to “/etc/cagefs/cagefs.mp” and remount the cagefs.

echo "/var/lib/mysql" >> /etc/cagefs/cagefs.mp
cagefsctl --remount-all

If you have moved the mysql folder to a different location then also you may see the same problem. In that case add the new folder path to cagefs e.g if you moved it to /home/mysql then add /home/mysql to cagefs.mp file