error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' — Missing /var/run/mysqld/mysqld.sock

后端 未结 30 2218
日久生厌
日久生厌 2020-11-22 10:49

My problem started off with me not being able to log in as root any more on my mysql install. I was attempting to run mysql without passwords turned on... but whenever I

相关标签:
30条回答
  • 2020-11-22 11:40

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

    in /etc/my.cnf add this lines:

    [client]
    socket=/var/lib/mysql/mysql.sock <= this path should be also same as is[mysqld]
    

    And restart the service with: service mysql restart

    this worked for me

    0 讨论(0)
  • 2020-11-22 11:44

    If you have a lot of databases and tables on your system, and if you have innodb_file_per_table set in my.cnf, then your mysql server might have run out of opened objects / files (or rather the descriptors for these objects) Set a new max number with

    open-files-limit = 2048
    

    and restart mysql. This approach might help when the socket is not created at all, but really this might not not be the real problem, there is an underlying problem.

    0 讨论(0)
  • 2020-11-22 11:44

    I had the exactly same issue. After struggling for an hour, I found a way of correcting it without reinstalling mysql-common, mysql-client, mysql-server.

    First of all, go to "/var/run/mysqld". You will find that the mysql.sock does not exist. Simply remove the entire mysqld directory and recreate it and provide it necessary privileges.

    # rm -rf /var/run/mysqld && mkdir /var/run/mysqld && chown mysql /var/run/mysqld/
    

    Now, Kill the mysql process in it's entirety. It might be possible that it will show you "waiting for page cleaner" on running "/etc/init.d/mysql status" command even after shutting down the service.

    To completely close the service, use

    # pkill -9 mysqld
    

    Once the process is killed, try starting it again using

    # /etc/init.d/mysql start
    

    And you will see that it works good! And also there will be no issue in stopping it too.

    0 讨论(0)
  • 2020-11-22 11:45

    In My case two mysqld processes were running.. killed the optional processs by using pkill -9 mysqld

    0 讨论(0)
  • 2020-11-22 11:46

    First create dir /var/run/mysqld

    with command:

    mkdir -p /var/run/mysqld
    

    then add rigths to the dir

    chown mysql:mysql /var/run/mysqld
    

    after this try

    mysql -u root
    
    0 讨论(0)
  • 2020-11-22 11:47

    Try the following at a terminal prompt:

    sudo mysql
    

    Once that lets you in, you can create a new user and grant privileges that you want on the specific database they need access to.

    Mysql 5.7 changed some things and by default uses the auth_socket plugin (as opposed to mysql_native_password) for root to protect the account from getting hacked. You can override this by setting the plugin field for root, but unless you have a very good reason you probably shouldn't circumvent the protection. Especially when sudo mysql is easier than mysql -u root -p anyway.

    I found out this info - of all places - from a Raspberry Pi help site. Worked like a charm after Lubuntu 18.04 annoyed the heck out of me for a couple hours.

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