9

A have already read everything about this error but I coundn't solve the problem.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)

I'm trying to install mysql on my Mac OsX but when I try to connect to the db (mysql -u root -p) I see this problem, ERROR 2002.

I have Mysql installed in /usr/local/mysql

7 Answers7

10

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 !!!

4

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.

4

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/...

Adam Bethke
  • 141
  • 4
1

I am using MacOX El Capitan 10.11.3 and I faced the above issue and none of the answers worked independently. I then tried a combination of user153254 and Adam's and it worked like a charm!

mysqld stop
mysql.server start
mysql -u root

Avoiding mysql -u root -p did the trick

Arnav
  • 11
1

main reason is mariadb/mysql is not running.

brew services start mariadb

OR

brew services start mysql

I solved same issue in MariaDB with bellow command. restart MariaDB/MySQL

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

I have installed MariaDB though homebrew. i have also restart my computer before running command.

enter image description here

Nanhe Kumar
  • 469
  • 4
  • 6
0

I had the exact same problem and I searched every possible site for solution to such problem and was not be able to solve it. However, today I did a simple command line from the Mac's Terminal that is I just typed in mysql -u root and then it solved the problem for me.

Let me know if this solution helps.

0

Provide hostname along with username and password

mysql -u <username> -p<password> -h <yourhostname>

enter image description here