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

I'm trying to run the mysql command on my mac osx but keep getting the error:

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

I did try researching this extensively but could'nt find a suitable solution. Most of the solutions refer to /etc/my.cnf but I don't seem to have this configuration file in the first place. I'm pretty much stuck and have been for quite a while. Any help is greatly appreciated.

share|improve this question

migrated from Nov 21 '11 at 9:43

This question came from our site for professional and enthusiast programmers.

uh, why did this 1 guy vote to close? this is a genuine problem i'm facing and badly need help. i don't see this as an being off-topic and am greatly appreciative of any help. – OckhamsRazor Aug 26 '11 at 11:25
Now you have 2 guys vote to close. This is not a deadly problem, google, please? – ajreal Aug 26 '11 at 11:27
'I did try researching this extensively'. He's obviously tried googling it. This is the point of StackOverflow I thought, find answers that google can't? I upvoted the question for ya ;) – Rob Quincey Aug 26 '11 at 11:31
Voted to close, because this question belongs on, not on stackoverflow. People on SF should be able to help you better than we can. – Johan Aug 26 '11 at 11:34
@Rob much appreciated mate. life's hard for a newbie here it seems... – OckhamsRazor Aug 26 '11 at 11:35
up vote 1 down vote accepted

In addition to ajreal's answer, check the "obvious" stuff...a lot of times you'll get this error when MySQL server isn't running, or you don't have permission to access it. Check in your process list to make sure it's running, seeing something like...

$ ps -ef |grep mysql
root      5325     1  0 13:09 ?        00:00:00 /bin/sh /usr/bin/mysqld_safe
mysql     5413  5325  0 13:09 ?        00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/ --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock
root      5415  5325  0 13:09 ?        00:00:00 logger -p daemon.err -t mysqld_safe -i -t mysqld

If you don't have permissions, try the command sudo chmod 775 /var/lib/mysql to elevate your permissions.

Or if it IS running, you may need to reinstall (yikes) but if you don't have much time, and scratching it is an option, use it as a last resort.

share|improve this answer
  1. check exist of socket /tmp/mysql.sock
  2. check mysql daemon is running
  3. check is it using / listening on port only

this could be serverfault area

ps afx | grep mysql   <--- this will show the mysql daemon command, 
                           you can make use of the information returned
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.