For homebrew mysql installs, how to fix mysql.sock path?


(Partho Biswas) #1

I am on macOS 10.12.3. Installed and running MySQL through Homebrew. Whenever i try to start MySQL with brew services start mysql or sudo mysql.server start command on terminal, it starts. Following is my my.cnf file residing into /etc/my.cnf

[mysqld]
user=mysql
basedir=/usr/local/Cellar/mysql/5.7.17
datadir=/usr/local/var/mysql
port=3306
server_id=1
socket=/tmp/mysql.sock

[client]
user=mysql
basedir=/usr/local/Cellar/mysql/5.7.17
datadir=/usr/local/var/mysql
port=3306
server_id=1
socket=/tmp/mysql.sock

Then i try to connect to MySQL using Perfect-MySQL following the instructions there. But failed to locate and connect to socket file. Got the following error,

[ERR] MySQL connection error: Can't connect to local MySQL server through socket '' (2)
[ERR] Error msg: error("MySQL server has gone away")

Clearly it failed to identify socket file path which should be /tmp/mysql.sock. But after running mysql server i found mysql.sock.lock.lock file into /tmp/ folder, there were no mysql.sock file.
Then i changed the my.cnf file with socket=/tmp/mysql.sock.lock.lock . but same result.

I have no other mysql client/service installed and tried freshly reinstalling with homebrew several times. Same result everytime.

I have tried with a lot of other options but no luck. CLearly i am missing something. Can someone please shade some light on it ?

How and from where i can set mysql.sock path ?


(Mike McQuaid) #2

What is in /usr/local/etc/my.cnf? How does it differ from /etc/my.cnf? Did you create a mysql user yourself? Try to run mysqld manually.


(Partho Biswas) #3

I didn’t find any file as /usr/local/etc/my.cnf
Yes, i tried creating user and also as root user. No luck.
When i enter mysqld on terminal, it says following…

mysqld: ready for connections.
Version: '5.7.17'  socket: '/tmp/mysql.sock'  port: 3306  Homebrew

But still getting the same result. I am going crazy with this issue. :frowning:


(Mike McQuaid) #4

You should try without your configuration file and using brew services start (without sudo) after restarting your computer and checking brew services list to make sure it’s not running before or after restart.


(Ben Claar) #5

I’ve noticed that the socket isn’t created if you restart mysql too quickly after stopping it:

brew services stop mysql;brew services start mysql
ls /tmp/mysql.sock // socket not created

Waiting 3 seconds before restarting mysql fixes this:

brew services stop mysql;sleep 3;brew services start mysql
sleep 1 // Note that it takes a second after mysql starts to create the socket
ls /tmp/mysql.sock // socket created!

(Gaojin) #6

hi, i have same error

How did I solve it?

  1. remove /usr/local/var/mysql/
  2. uninstall mysql
  3. install mysql