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

前端 未结 30 1679
南方客
南方客 2020-11-22 11:30

I am getting the following error when I try to connect to mysql:

Can\'t connect to local MySQL server through socket \'/var/lib/mysql/mysql.sock\' (2)<

30条回答
  •  旧巷少年郎
    2020-11-22 11:51

    One way to reproduce this error: If you meant to connect to a foreign server but instead connect to the non existent local one:

    eric@dev ~ $ mysql -u dev -p
    Enter password:
    ERROR 2002 (HY000): Can't connect to local MySQL server through 
    socket '/var/lib/mysql/mysql.sock' (2)
    eric@dev ~ $
    

    So you have to specify the host like this:

    eric@dev ~ $ mysql --host=yourdb.yourserver.com -u dev -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 235
    Server version: 5.6.19 MySQL Community Server (GPL)
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> show databases;
    +-------------------------+
    | Database                |
    +-------------------------+
    | information_schema      |
    | mysql                   |
    | performance_schema      |
    +-------------------------+
    3 rows in set (0.00 sec)
    
    mysql> exit
    Bye
    eric@dev ~ $
    

提交回复
热议问题