I recently tried installing MySQL with homebrew (
brew install mysql) and when I try to run it I get the following error:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
There is no
/tmp/mysql.sock nor a
I’ve searched and haven’t found any
How can I fix this?
When you got the server running via
you should see the socket in /tmp/mysql.sock. However, the system seems to expect it in /var/mysql/mysql.sock. To fix this, you have to create a symlink in /var/mysql:
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
This solved it for me. Now my phpMyAdmin works happily with localhost and 127.0.0.1.
Credit goes to Henry
Looks like your mysql server is not started. I usually run the stop command and then start it again:
mysqld stop mysql.server start
Same error, and this works for me.
Try to connect using “127.0.0.1” instead “localhost”.
1) If you are able to start mysql with below command;
mysql server start
2) and if you are able to see “mysql stopped” when you run below command;
brew services list
than, adding mysql to services will fix your problem. With this method, mysql will start as service when your system started. To do so you can run below command;
brew services start mysql
After that, you can restart your system and try connecting to mysql. I did the same and stop receiving below error;
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket
I hope this helps.
I got the same error and this is what helped me:
$ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents $launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist $mysql -uroot mysql>
You’ll need to run
mysql_install_db – easiest way is if you’re in the install directory:
$ cd /usr/local/Cellar/mysql/<version>/ $ mysql_install_db
Alternatively, you can feed
basedir parameter like the following:
$ mysql_install_db --basedir="$(brew --prefix mysql)"
I faced the same problem on my mac and solved it, by following the following tutorials
But don’t forget to kill or uninstall the old version before continuing.
brew uninstall mariadb xcode-select --install ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - See more at: https://mariadb.com/resources/blog/installing-mariadb-10116-mac-os-x-homebrew#sthash.XQoxRoJp.dpuf brew doctor brew update brew info mariadb brew install mariadb mysql_install_db mysql.server start
Just to add to these answers, In my case I had no local mySQL server, it was running inside a docker container. So the socket file does not exist and will not be accessible for the “mysql” client.
The sock file gets created by mysqld and mysql uses this to communicate with it.
However if your mySql server is not running local, it does not require the sock file.
By specifying a host name/ip the sock file is not required e.g.
mysql --host=127.0.0.1 --port=3306 --user=xyz --password=xyz
just to complete this thread.
therefore MAMP (PRO) is used pretty often
the path here is