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

后端 未结 30 2214
日久生厌
日久生厌 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:21

    There is a lots of reason for this issue, but sometimes just restart the mysql server, it will fix the issue.

    sudo service mysql restart
    
    0 讨论(0)
  • 2020-11-22 11:22

    Changing the host to 127.0.0.1 worked for me.

    Edit the file in /etc/mysql/my.cnf and add the below mentioned line to the section: client

    [client]
    port  = 3306
    host  = 127.0.0.1
    socket  = /var/lib/mysql/mysql.sock
    

    After you are done with it. Execute the following command.

    sudo service mysql start
    
    0 讨论(0)
  • 2020-11-22 11:23

    The answer of the user load step worked for me. Sometimes is need edit the file in /etc/mysql/my.cnf add line to client

    [client]
    password = your_mysql_root_password
    port  = 3306
    host  = 127.0.0.1
    socket  = /var/lib/mysql/mysql.sock
    
    0 讨论(0)
  • 2020-11-22 11:23

    I would also check the mysql configuration. I was running into this problem with my own server but I was a bit too hasty and misconfigured the innodb_buffer_pool_size for my machine.

    innodb_buffer_pool_size = 4096M

    It usually runs fine up to 2048 but I guess I don't have the memory necessary to support 4 gigs.

    I imagine this could also happen with other mysql configuration settings.

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

    To find all socket files on your system run:

    sudo find / -type s
    

    My Mysql server system had the socket open at /var/lib/mysql/mysql.sock

    Once you find where the socket is being opened, add or edit the line to your /etc/my.cnf file with the path to the socket file:

    socket=/var/lib/mysql/mysql.sock
    

    Sometimes the system startup script that launched the command line executable specifies a flag --socket=path. This flag could override the my.cnf location, and that would result in a socket not being found where the my.cnf file indicates it should be. Then when you try to run the mysql command line client, it will read my.cnf to find the socket, but it will not find it since it deviates from where the server created one. So, Unless you care where the socket resides, just changing the my.cnf to match should work.

    Then, stop the mysqld process. How you do this will vary by system.

    If you're super user in the linux system, try one of the following if you don't know the specific method your Mysql setup uses:

    • service mysqld stop
    • /etc/init.d/mysqld stop
    • mysqladmin -u root -p shutdown
    • Some systems aren't setup to have an elegant way to stop mysql (or for some reason mysql doesn't respond) and you can force terminate mysql with either:
      • One step: pkill -9 mysqld
      • Two step (least preferred):
        • Find the process id of mysql with either pgrep mysql or ps aux | grep mysql | grep -v grep
        • Assuming the process id is 4969 terminate with kill -9 4969

    After you do this you might want to look for a pid file in /var/run/mysqld/ and delete it

    Make sure the permissions on your socket is such that whatever user mysqld is running as can read/write to it. An easy test is to open it up to full read/write and see if it still works:

    chmod 777 /var/run/mysqld/mysqld.sock
    

    If that fixes the issue, you can tailor the permissions and ownership of the socket as needed based on your security settings.

    Also, the directory the socket resides in has to be reachable by the user running the mysqld process.

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

    Using XAMPP on ubuntu:

    1. Create a folder called mysqld inside /var/run directory. You can accomplish that using the command sudo mkdir /var/run/mysqld.

    2. Create a symbolic link to mysql.sock file that is created by the XAMPP server when it is started. You can use the command sudo ln -s /opt/lampp/var/mysql/mysql.sock /var/run/mysqld/mysqld.sock.

    Note: The mysql.sock file is created when the server is started and removed when the server is stopped, so sometimes the link you created might appear to be broken but it should work as long as you have started the server using either sudo /opt/lampp/lampp start or any other means.

    1. Start the server if it's not already running and try executing your program again.

    Good luck! I hope you'll get away with it this time.

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