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

后端 未结 30 1454
再見小時候
再見小時候 2020-11-30 23:15

I\'m getting this error

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

even though

相关标签:
30条回答
  • 2020-12-01 00:12

    Two main reasons:

    1) mysql-server isn't installed! You have to install it (mysql-server and not mysql-client) and run it.

    2) It's installed by default and running. So, it's not possible to run it again through Xampp or Lampp. You have to stop it: sudo service mysql stop

    then you can start it through Xampp. It's possible to check if it's running or not with this code: sudo netstat -tap | grep mysql

    If you see a result like this: tcp 0 0 localhost:mysql : LISTEN 1043/mysqld

    It means that it's running properly.

    0 讨论(0)
  • 2020-12-01 00:13

    The client should be set consistent with server setting.

    [client]
    port        = 3306
    socket      = /var/run/mysqld/mysqld.sock
    
    [mysqld]
    user        = mysql
    pid-file    = /var/run/mysqld/mysqld.pid
    socket      = /var/run/mysqld/mysqld.sock
    port        = 3306
    
    0 讨论(0)
  • 2020-12-01 00:14

    In the linux terminal, I run the following steps and they helped me out

    1.First of all list all the mysql packages installed

      sudo dpkg -l | grep mysql
    

    2.Delete the listed packages with the listed command

      sudo apt-get --purge autoremove <package name>
    

    3.Reinstall mysql server

      sudo apt-get install mysql-server
    

    This worked for me, Hope this works for you aswell.

    Alternatively Try

    sudo apt-get remove --purge mysql-\
    

    then reinstall with

    sudo apt-get install mysql-server mysql-client
    
    0 讨论(0)
  • 2020-12-01 00:17

    I also met this problem. mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

    Then I find the reason is my selinux is enforcing, I disable it then restart mysqld , it works, hope helpful.

    0 讨论(0)
  • 2020-12-01 00:18

    This took me ages to figure out but could you try the same -

    1 - Update and Upgrade

    sudo apt-get update
    sudo apt-get upgrade
    

    2 - Purge MySQL Server and Client (if installed).

    sudo apt-get purge mysql-server mysql-client
    

    3 - Install MySQL Server and Client fresh

    sudo apt-get install mysql-server mysql-client
    

    4 - Test MySQL

    mysql -u root -p
    > enter root password
    

    *** should get socket not found in /var/run/mysqld/mysql.sock

    4 - Configure mysqld.cnf with nano of vi

    sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

    Change bind-address from 127.0.0.1 to localhost

    bind-address            = localhost
    

    ** Write and Exit

    5 - Restart MySQL

    sudo /etc/init.d/mysql restart
    

    6 - check mysql

    mysql -u root -p
    > enter root password
    
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)
    
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    

    You should get in to mysql cli now.

    Hope this helps

    Code.Ph0y

    0 讨论(0)
  • 2020-12-01 00:20

    You may be missing mysql-server. install it using

    sudo apt-get install mysql-server
    
    0 讨论(0)
提交回复
热议问题