I have changed the location of the socket file in my.cnf, however, when I try to login to mysql, I get the error "Can't connect to local MySQL server through socket 'prev/sock'" (I am using Prev/sock to denote that it is still looking for the previous location/default location).

I have added this parameter in my.cnf file


I am using [mysqld] in my.cnf, not [client]

when I try using the command:

mysql -u root -p -S /opt/data/sockpid/mysql.sock - this bit is working

The parameter is not being read or not working correctly...

1 Answer 1


If you change the location of the socket file in the [mysqld] section, you must also change it in the [client] section, or else clients will default to the original location.

As you said, you can specify a socket path when using the client, and that takes precedence over the configuration file or the default.

  • I don't have a client section...
    – dbafix
    Commented Jun 23, 2023 at 6:22
  • Use a text editor and add one. Commented Jun 23, 2023 at 6:46

Your Answer

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

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