# MySQL 5.7 - Unable to change socket directory



## Mayhem30 (Apr 25, 2021)

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?


----------



## ShelLuser (Apr 25, 2021)

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.


----------



## dbdemon (Apr 25, 2021)

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


----------



## dbdemon (Apr 26, 2021)

Mayhem30 said:


> 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.)


----------



## Datapanic (Apr 26, 2021)

Can we see the my.cnf file - just the parts under where the socket lines should be?

It should be something like:


```
[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.


----------



## Mayhem30 (Apr 26, 2021)

This is what it looks before I make the changes in both spots (which works).


```
[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
...
...
```


----------



## Datapanic (Apr 26, 2021)

I can't dupe the problem.  I use Percona 5.7 on all my DBs on FreeBSDs 11.4 and 12.2.


----------



## Mayhem30 (Apr 26, 2021)

dbdemon said:


> 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.:
> 
> ...



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.


----------



## SirDice (Apr 26, 2021)

Mayhem30 said:


> but all my live websites can't unless socket is set to /tmp/mysql.sock


See /usr/local/etc/php.ini:

```
[Pdo_mysql]
; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
pdo_mysql.default_socket=
```


----------



## Mayhem30 (Apr 26, 2021)

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.


----------



## SirDice (Apr 26, 2021)

Mayhem30 said:


> I don't use PDO - I just stick with MySQLi.


Similar setting:

```
[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 =
```


----------

