Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
Have you checked that the mysqld process is running? – pconcepcion Dec 19 '12 at 13:25
When I write: mysql start, mysql gives me this error ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38) – Rafael Pontes Dec 19 '12 at 13:32
when I write /Library/StartupItems/MySQLCOM/MySQLCOM start It says Starting MySQL database server but in MYSQLPANEL on mac says: The mysql server instance is stopped. – Rafael Pontes Dec 19 '12 at 13:34
it's a bit tricky sometimes to start MySQL on Mac OS X, I've write you one possible way to do it, hope it helps. – pconcepcion Dec 19 '12 at 14:19
up vote 2 down vote accepted

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.

share|improve this answer
Ok a did this and now I have this: 0 8308 1 0 0:00.08 ?? 0:00.11 /bin/sh /usr/local/mysql/bin/mysqld_safe – Rafael Pontes Dec 19 '12 at 15:03
But still happen the same problem. There is 2 folders inside /usr/local/mysql: mysql/ and mysql-5.5.28-osx10.6-x86_64/. Is That a problem? – Rafael Pontes Dec 19 '12 at 15:05
@RafaelPontes if you can see that output from the ps command is that the daemon is running, try @RolandoMySQLDBA solution... you can also check the configuration file (usually /etc/my.cnf) and be sure the mysqld daemon is using that socket (/tmp/mysql.sock) – pconcepcion Dec 19 '12 at 19:32
Sorry, I thought that when I use sudo /usr/local/mysql/bin/mysqld_safe & it worked, but just now I saw this error: – Rafael Pontes Dec 19 '12 at 20:42
mysqld_safe Logging to '/var/lib/mysql/Rafaels-MacBook-Pro.local.err'. 121219 17:35:59 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 121219 17:36:03 mysqld_safe mysqld from pid file /var/run/mysqld/ ended – Rafael Pontes Dec 19 '12 at 20:42

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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.