0
votes

When i am trying to login in mysql shell using

mysql -u root -p

i am getting the

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

Please help me out what is wrong with mysql

I am able to login using mysql --host=127.0.0.1 frontend

Update /etc/hosts

  127.0.0.1       localhost
    127.0.1.1       shweta-desktop
    127.0.0.1       webfaction
    # The following lines are desirable for IPv6 capable hosts
    ::1     ip6-localhost ip6-loopback
    fe00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
3
please add your /etc/hosts file to the question - Jojo
netstat -ln | grep mysql will tell you where the socket path is - guido

3 Answers

1
votes

I found that it was because the mysql database wasn't running use this command to start it

service mysqld start
0
votes

The answer of sandhaya is not wrong, regarding your comment there. See this answer on Serverfault and the comments: https://serverfault.com/questions/295285/mysql-cannot-connect-via-localhost-only-127-0-0-1

To summarize it: If you connect to mysql with the special vhost-name "localhost" (which is the default), mysql tries to connect to the socket specified in your /etc/my.conf. This seems to be an incorrect one. What´s wrong with your your host-alias i cannot say, your /etc/hosts seems correct. So connecting with 127.0.0.1 is actually a solution, the other is to find the correct soccet and place it in your /etc/my.conf.

0
votes

I was having this issue. I found that I had a .netrc in /root that had info in it.

I deleted it and problem gone.

Able to log into mysql using mysql -uroot -p without issue now.