16

I have a mysql.sock file located at:

/tmp/mysql.sock

But the my.cnf is pointing to this location:

socket=/var/lib/mysql/mysql.sock

Is this correct?

3
  • No there is no '/var/lib/mysql/mysql.sock file
    – Victor
    Oct 27, 2015 at 21:05
  • The order of path that mysql searches for configuration is /var/lib/mysql/my.cnf, /etc/my.cnf, ~mysql/.my.cnf.
    – alvits
    Oct 27, 2015 at 21:47
  • In some cases the file you're looking for might be called mysqld.sock instead. This is at least the case for Ver 14.14 Distrib 5.7.22, for Linux (x86_64) on Ubuntu 16.04 May 30, 2018 at 16:07

2 Answers 2

40

The socket declaration should be located under [mysqld] in your my.cnf. If you have declared it there and still pointing to another place such as tmp, then your my.cnf file that you have been editing is not being read when mysql starts or there is another my.cnf overriding the one you have been editing. The case may also be that there is a second Socket declaration in the same my.cnf file that is overriding the one you expect to be read at start by mysql.

You can check its absolute path by logging into mysql and running:

mysql> show variables like 'socket';
+-----------------------------------------+-------------------------------+
| Variable_name                           | Value                         |
+-----------------------------------------+-------------------------------+
| socket                                  | /yourpath/mysql.sock          |
+-----------------------------------------+-------------------------------+
1 rows in set (0.00 sec)
1
  • 3
    you are awesome. Apr 22, 2019 at 20:31
1

There is no right or wrong place on linux for saving sockets, except on external devices which are unmounted at any time or folders which are emptied from time to time. You need to configure where you want to place it.

For the MySQL console client there is something more to consider: The client seems to use the socket configuration value provided in [client] instead of [mysqld]. If you have a multiple MySQL server setup like i have (4.1, 5.5, 5.7), you probably want to use a "--defaults-extra-file" option with the socket written in the [client] part for each different server. The socket needs to be the same as the one defined in the my.cnf [mysqld] part used on the server. Here is an example defaults-extra-file.cnf, remember to change the user, password and socket to your needs - and keep it on access rights 400 (there is a password stored after all):

[client]
user = guardian
password = I-4m.Gr00t!
host = localhost
socket = /var/run/mysqld/mysqld-5.6.sock

This only applies though if you are using "localhost" as the value for "host". If you have multiple local addresses (127.0.0.2, 127.0.0.3), you need to leave the config variable for "host" on "localhost" to use the configured socket. Otherwise the client will connect to the server using TCP.

This was tested on my Debian 9.5 Server with MySQL 4.1.22, 5.5.49 and 5.7.19 and their respective clients.

1
  • Hi, "There is no right or wrong place on linux for saving sockets, except on external devices which are unmounted at any time": does this apply too to external discs automounted in /mnt/? I'having issues to connect with sockets unless using "sudo"... Thanks
    – lbrutti
    Nov 25, 2021 at 17:20

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.