Cannot connect to local MySQL server through socket

I get the following error

error: "Cannot connect to the local MySQL server through the socket '/var/lib/mysql/mysql.sock' (2) '

How to recover mysql.sock file?

[change]

I am trying to connect to mysql database from my ROR application. He worked until yesterday. But today I found out that the mysql.sock file is missing. I do not know the reason why the mysql.sock file was deleted from location / var / lib / mysql /. How to recover mysql.file?

Thanks.....

+2
source share
3 answers

Try the following:

$ mysql_config |grep -- --socket 

It should show the socket path compiled to the server. If this fails, try running the mysql command and find the socket path at \s output.

+6
source

here is a rough but quick way to solve this problem, but if your data or operation is important, you better find another way

  • kill the whole mysql process

  • now your mysql should be stopped but blocked.

    So delete the lock file and restart mysqld

    rm /var/lock/subsys/mysqld

    /etc/init.d/mysqld start

+1
source

I had the same problem, and after spending some time, I got a solution. Run this command from your terminal - sudo apt-get install mysql-server

0
source

All Articles