Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

[mysqld]
datadir=/media/ephemeral0/data/mysql
socket=/media/ephemeral0/data/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# adding more config
skip-external-locking
long_query_time=1
slow_query_log
slow_query_log_file=/var/log/log-slow-queries.log
log-bin=mysql-bin
server-id= 1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
myisam_recover_options

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!

share|improve this question
    
try: socket=/var/lib/mysql/mysql.sock –  Prince John Wesley 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? –  RakeshS 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

1 Answer 1

up vote 2 down vote accepted

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:

http://dev.mysql.com/doc/refman/5.1/en/option-files.html

share|improve this answer
    
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

 
discard

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.