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

后端 未结 30 1453
再見小時候
再見小時候 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-11-30 23:53

    I have the same problem and tried all the solutions posted here like :

    sudo apt-get autoremove mysql-server
    

    but unfortunately it doesn't work for me on ubuntu 16.04. To uninstall the right package you need to :

    sudo apt-get remove mysql-
    

    when you tried to autocomplete using tab the command it will list the following package :

    mysql-client           mysql-client-core-5.7  mysql-server           mysql-server-core-5.7  mysql-workbench        mythes-en-us           
    mysql-client-5.7       mysql-common           mysql-server-5.7       mysql-utilities        mysql-workbench-data   
    

    obviously choose the mysql-server-core-5.7 so it would be :

    sudo apt-get remove mysql-server-core-5.7
    

    and now you can uninstall all mysql and reinstall again using these command from johnny's answer :

    sudo apt-get remove --purge mysql*
    sudo apt-get autoremove
    sudo apt-get autoclean
    sudo apt-get install mysql-server mysql-client
    

    Now I solved it and the Error is GONE.

    0 讨论(0)
  • 2020-11-30 23:54

    This problem will occurred due to some unnecessary changes made in my.cnf file. Try to diff /etc/mysql/my.cnf with one of working mysql servers my.cnf file.

    I just replaced /etc/mysql/my.cnf file with new my.cnf file and this works for me.

    0 讨论(0)
  • 2020-11-30 23:57

    Firstly, please confirm mysql-server is installed. I have the same error when mysql-server is installed but corrupted somehow. I do the trick by uninstall mysql completely and reinstall it.

    sudo apt-get remove --purge mysql*
    sudo apt-get autoremove
    sudo apt-get autoclean
    sudo apt-get install mysql-server mysql-client
    
    0 讨论(0)
  • 2020-11-30 23:57

    I had the same problem after altering my.cnf. I resolved this problem next steps.

    First : to find the location of error.log, look at 'my.conf'.

    Second : I looked up error.log, I found next massages,

    "unknown variable 'default-......' " ..... " mysqld_safe Starting mysqld darmon with from /var/lib/mysql "

    Third : I reset my.conf to the default, then restart, this problem was resolved.

    I hope this helps.

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

    This is an old tread with different solution proposed, but none of them worked for me. I'm adding this answer in the hope it will help somebody who struggled as me for some time.

    I've checked all the existing answers and all the existing solution, but for me the issue was incorrect user permission on var/run/mysql folder.

    I've checked the user permission on that folder and it was set to root. Once i changed to mysql:mysql the problem has gone.

    So enter into /var/run/mysqld and change the user permission to:

    chown -R mysql:mysql .
    
    0 讨论(0)
  • 2020-12-01 00:01

    Simple: run these codes:::

     1:: ls -lart/var/run/my*
    
       2::mkdir /var/run/mysqld
    
        3::touch /var/run/mysqld/mysqld.sock
        4:ls -lart /var/run/mysqld
        5::chown -R mysql /var/run/mysqld
        6::ls -lart /var/run/mysqld
    REstart your mysql server
    

    then finaly type mysql -u root or mysql -u root -p and press enter key. thanks

    0 讨论(0)
提交回复
热议问题