MySQL 5.7 - Unable to change socket directory

I'm trying to change the socket directory from /tmp/mysql.sock to /var/run/mysql/mysql.sock.

I first created the directory (/var/run/mysql/) and changed owner to mysql:mysql + chmod 755.

Then I changed the 2 socket lines in /usr/local/etc/mysql/my.cnf file and restarted the server.

Now I am unable to connect to the server. No errors during startup, no errors in the MySQL error log and the mysql.sock files are showing in the /var/run/mysql/ directory.

Changing socket directory back to /tmp/mysql.sock fixes the issue.

Any ideas how to troubleshoot this?
 
Did you change the socket entry for both the server and client? If you only change the server then the client will still use the default socket location.
 
What's the error you get when you try to connect?

Are you able to connect when specifying the socket file to use on the command line, i.e.:

mysql -S /var/run/mysql/mysql.sock

Are you able to connect over TCP?

mysql --protocol=tcp
 
Then I changed the 2 socket lines in /usr/local/etc/mysql/my.cnf file and restarted the server.
I've never actually used MySQL on FreeBSD, so I don't know what the default my.cnf file looks like, but you should be able to specify the socket in just a single line if you specify it in the [client-server] section of the file. (You can then delete the other lines specifying the socket.)
 
Can we see the my.cnf file - just the parts under where the socket lines should be?

It should be something like:

Code:
[client]
socket                         = /var/run/mysql/mysql.sock

[mysqld]
socket                         = /var/run/mysql/mysql.sock
You can also enable logging to see if there's any clues there.
 
This is what it looks before I make the changes in both spots (which works).

Code:
[mysqld_safe]
malloc-lib=/usr/local/lib/libtcmalloc_minimal.so

[mysql]

# CLIENT #
# port                         = 3306
socket                         = /tmp/mysql.sock
max_allowed_packet             = 16M
no-auto-rehash

[mysqldump]
quick
max_allowed_packet             = 16M

[mysqld]

skip-networking
skip-name-resolve

# this is being used to temp tables (1 GB tmpfs ram disk)
tmpdir = /ram

# GENERAL #
....
socket                         = /tmp/mysql.sock
...
...
 
What's the error you get when you try to connect?

Are you able to connect when specifying the socket file to use on the command line, i.e.:

mysql -S /var/run/mysql/mysql.sock

Are you able to connect over TCP?

mysql --protocol=tcp

I am able to connect to MySQL via command line using mysql -S /var/run/mysql/mysql.sock, but all my live websites can't unless socket is set to /tmp/mysql.sock

TCP is disabled, I only use socks.
 
but all my live websites can't unless socket is set to /tmp/mysql.sock
See /usr/local/etc/php.ini:
Code:
[Pdo_mysql]
; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
pdo_mysql.default_socket=
 
I don't use PDO - I just stick with MySQLi.

I've pretty much tried everything and it just refuses to connect. The fact that it doesn't throw any errors (with the exception in the Apache logs complaining that MySQLi does not exist) really surprises me. It restarts without any issues either.
 
I don't use PDO - I just stick with MySQLi.
Similar setting:
Code:
[MySQLi]

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/mysqli.default-socket
mysqli.default_socket =
 
Back
Top