2

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!

Arth
  • 365
  • 1
  • 5
  • 15

2 Answers2

2

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

HBruijn
  • 77,029
  • 24
  • 135
  • 201
  • 2
    Yours is probably the best answer because it covers the connection default for all PHP applications, however phpMyAdmin also allows one to configure the socket path directly, in `config.inc.php` with the directive `$cfg['Servers'][$i]['socket'] = '/home/mysql/mysql.sock';` – ibennetch Apr 01 '16 at 02:36
0

As ibennetch suggested in his comment above, setting the socket path to the new location woks. In my case the default setting for connection type was 'tcp'. That also needs to be changed to 'socket'.

Thus the two lines that need to be changed in the config.in.php file are:

$cfg['Servers'][$i]['socket'] = '/home/mysql/mysql.sock';
$cfg['Servers'][$i]['connect_type'] = 'socket';

Don't forge to restart httpd:

systemctl restart httpd