Symptoms
Sites that use localhost as the database host will encounter database connection errors while switching to 127.0.0.1 allows for a successful connection.
Cause
Scripts will try to connect to the Unix socket if configured to connect to localhost. They try to connect to the network socket if configured to connect to 127.0.0.1 or another IP address. The socket a script connects to doesn't matter unless CageFS is used. CageFS restricts what resources users have access to. If CageFS isn't configured to allow access to the folder the mysql.sock file is in, scripts attempting to connect to the MySQL Unix socket will encounter connection errors.
Resolution
- Access the server's command line as the 'root' user via SSH or "Terminal" in WHM.
- Open
/etc/my.cnfin your preferred text editor. -
Ensure that the
datadirandsocketentries exist and have the correct values.CONFIG_TEXT: datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sockNote: Please note that the above values are the default values and must be replaced with the values specific to your server.
- Save the changes and exit the text editor.
-
Restart the mysqld service if changes were made to
/etc/my.cnf.# /usr/local/cpanel/scripts/restartsrv_mysql
- Open
/etc/cagefs/cagefs.mpin your preferred text editor. -
Ensure that the
/var/lib/mysqlentry exists.Note: Please note that if the MySQL socket file is not in the default folder, replace the path
/var/lib/mysqlwith the folder the socket file is located in. - Save the changes and exit the text editor.
-
Remount and update CageFS for all users.
# cagefsctl -M
# cagefsctl --force-update
Comments
0 comments
Article is closed for comments.