ERROR 2002 MYSQL socket /tmp/mysql.sock

You say you get the error when you run mysql -u root -p

This will look for a socket file to connect. When mysqld started up, it is possible for the socket file not to be made and still have mysqld start up ( See my post Percona-server time out on /etc/init.d/mysql start )

Try using one of the following to see if you can connect without a socket file

  • mysql -u root -p -h127.0.0.1
  • mysql -u root -p -h127.0.0.1 --protocol=tcp

If you can connect with one of these, the shutdown mysql like this

mysqladmin -u root -p -h127.0.0.1 --protocol=tcp shutdown

mysqld should shutdown properly. Afterwards, startup mysql as usual

Give it a Try !!!

Check the MySQL daemon is running

You can check if the mysqld daemon from **Terminal Application* running:

ps -feax | grep mysqld 

And verifying that you get something similar to this:

    0  8308     1   0   0:00.08 ??         0:00.11 /bin/sh /usr/local/mysql/bin/mysqld_safe

or looking for a mysqld process on the Activity Monitor application

If it's not running you have to start the daemon.

Start MySQL daemon

On Mac OSX you can start the daemon from the Terminal Application with something like this:

sudo /usr/local/mysql/bin/mysqld_safe &

Again check that now the MySQL daemon is running as described before.

I know this is an older post, but I spent the last hour or so bouncing back and forth between serverfault, StackOverflow, and DataBase administrators trying to figure out how to solve this issue after installing on Mac (El Capitan) using homebrew.

At least in my case, the advice from this post worked:

# Run the following commands
mysqld stop
mysql.server start

From what I can gather, I think (at least in my case) brew mysql hadn't initialized the permanent socket and my network admin locked down the ability to connect new processes via /tmp/...