When I try to log into mysql locally using the command:

mysql -u root -p

I get this error:

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

I can access the server remotely(not as root) and my web pages are using the mysql fine, but locally I cannot log on(which I need because I need to create some users). Only change I made was to attach another drive to the server and move the sql data there. Here's my.cnf

# Disabling symbolic-links is recommended to prevent assorted security risks

# adding more config
server-id= 1


I read I need to edit the socket info in my.cnf to make sure it points to the right socket file..I double checked and the file exists(although it starts with an S when I do ls -l "srwxrwxrwx 1 mysql mysql 0 Jun 21 03:43 mysql.sock").

I'm not really sure how to resolve this. I have tried to reboot and ran yum update to make sure I was running the latest packages.

Please help!

  • try: socket=/var/lib/mysql/mysql.sock Jun 21 '11 at 4:16
  • 1
    Thanks john it worked. okay I just realized you got that path from the error(sorry not sure why I didn't get that either) but is there a reason its picking that location instead of the one I specified? also can you put your comment as an answer so I can accept it.
    – Lostsoul
    Jun 21 '11 at 4:19
  • did you make sure you restarted MySQL after changing your my.cnf? Jun 21 '11 at 4:32
  • yes i did..I restarted the entire server as well..it didn't work, it was still using the path above instead of the one in my.cnf
    – Lostsoul
    Jun 21 '11 at 5:02

The problem is that in the [mysqld] section of your my.cnf you have set the socket to a non-standard location of /media/ephemeral0/data/mysql/mysql.sock but the [mysqld] section only affects the server and not the client.

You should put that option in the [mysql] section instead - then it will apply to both the client and the server.

You can find more information on option files and the sections in them in the mysql documentation:


  • Thank you, that worked and I understand the problem now. I didn't know all the options, when I changed the file, I just read the old settings and swapped them with the new ones. Thanks alot.
    – Lostsoul
    Jun 21 '11 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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