ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
I installed MySQL on Mac OS X Mountain Lion with
homebrew install mysql, but when I tried
mysql -u root I got the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
What does this error mean? How can I fix it?
It's probably because MySQL is installed but not yet running.
To verify that it's running, open up Activity Monitor and under "All Processes", search and verify you see the process "mysqld".
You can start it by installing "MySQL.prefPane".
Here is the complete tutorial which helped me: http://obscuredclarity.blogspot.in/2009/08/install-mysql-on-mac-os-x.html
You'll need to start MySQL before you can use the
mysql command on your terminal. To do this, run
brew services start mysql. By default, brew installs the MySQL database without a root password. To secure it run:
To connect run:
root is the username name here.
Read more... Read less...
This happened after the homebrew install and occurs due to permission issues. The following commands fixed the issue.
sudo chown -R _mysql:mysql /usr/local/var/mysql sudo mysql.server start
brew info mysql
And follow the instructions. From the description in the formula:
Set up databases to run AS YOUR USER ACCOUNT with: unset TMPDIR mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp To set up base tables in another folder, or use a different user to run mysqld, view the help for mysql_install_db: mysql_install_db --help and view the MySQL documentation: * http://dev.mysql.com/doc/refman/5.5/en/mysql-install-db.html * http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html
Hope this helps.
As others have pointed out this is because MySQL is installed but the service isn't running. There are many ways to start the MySQL service and what worked for me is the below.
To start the service:
- Go to "System Preference"
- At the bottom pane there should be MySql icon.
- Double click that to launch the 'MySQL Server Status' and press the button 'Start MySQL Server'
Mac Yosemite 10.10.3
Installed Package: /Volumes/mysql-advanced-5.6.24-osx10.8-x86_64
Solutions revolve around:
changing MySQL's permissions
sudo chown -R _mysql:mysql /usr/local/var/mysql
Starting a MySQL process
sudo mysql.server start
Just to add on a lot of great and useful answers that have been provided here and from many different posts, try specifying the host if the above commands did not resolve this issue for you, i.e
mysql -u root -p h127.0.0.1
Warning - this method will remove all of your databases in the
I had MySQL installed with Homebrew, and the only thing that fixed this for me was re-installing MySQL.
On my company laptop, I didn't have permission to uninstall MySQL from my computer via Homebrew:
$ brew uninstall mysql --ignore-dependencies Uninstalling /usr/local/Cellar/mysql/8.0.12... (255 files, 233.0MB) Error: Permission denied @ dir_s_rmdir - /usr/local/Cellar/mysql/8.0.12
So instead, I removed and reinstalled MySQL manually:
$ sudo rm -rf /usr/local/Cellar/mysql $ brew cleanup $ sudo rm -rf /usr/local/var/mysql $ brew install mysql
And that worked!