Mysql – Centos 6; phpMyAdmin ‘Cannot log in to the MySQL server’ after moving thesql.sock

centos6MySQLphpmyadminsocketunix

I recently moved my mysql datadir from /var/lib/mysql to a new directory /home/mysql mounted on a new hard drive.

For neatness sake I thought it'd be nice to place the tmpdir and socket on this new hard drive.

Everything works as planned, until I moved the socket file. Moving the socket file prevents phpMyAdmin from logging in; I can login fine from the command line and using my web framework, just not with phpMyAdmin.

The only difference between a working configuration and not is in my my.cnf file..

Working:

[mysqld]
socket = /var/lib/mysql/mysql.sock 

...

[client]
socket = /var/lib/mysql/mysql.sock

Not:

[mysqld]
socket = /home/mysql/mysql.sock 

...

[client]
socket = /home/mysql/mysql.sock

Assuming this is a permissions error I checked the paths of each location:

drwxr-xr-x. root  root  var
drwxr-xr-x. root  root  lib
drwxr-xr-x  mysql mysql mysql
srwxrwxrwx  mysql mysql mysql.sock

drwxr-xr-x. root  root  home
drwxr-xr-x  mysql mysql mysql
srwxrwxrwx  mysql mysql mysql.sock

so I'm guessing they are OK. Have I assumed wrong?

I phpMyAdmin configured to use 'localhost' I have the mysql bind-address option set to our local network IP for the server (192.168.etc.)

I also restarted both the httpd and mysqld servers when testing a new config.

I'm quite happy to leave the socket file where it is, assuming this isn't a security/performance issue, but would love to know what is going on if anyone can help shed some light!

Best Answer

Unless you use the built-in default location PHP also needs to be explicitly configured with the location of the MySQL socket file in the php.ini file or in the connection string...

pdo_mysql.default_socket= /home/mysql/mysql.sock

or depending on your choice of API's

mysqli.default_socket= /home/mysql/mysql.sock