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

前端 未结 30 1290
南方客
南方客 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:45

    if you change files in /var/lib/mysql [ like copy or replace that ], you must set owner of files to mysql this is so important if mariadb.service restart has been faild

    chown -R mysql:mysql /var/lib/mysql/*

    chmod -R 700 /var/lib/mysql/*

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

    ran into this issue while trying to connect mysql in SSH client, found adding the socket path to the command helpful when switching between sockets is necessary.

    > mysql -u user -p --socket=/path/to/mysql5143.sock
    
    0 讨论(0)
  • 2020-11-22 11:46

    try

    echo 0 > /selinux/enforce
    
    0 讨论(0)
  • 2020-11-22 11:47

    Please ensure you have installed MySQL server correctly, I met this error many times and I think it's complicated to debug from the socket, I mean it might be easier to reinstall it.

    If you are using CentOS 7, here is the correct way to install it:

    First of all, add the mysql community source
    yum install http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

    Then you can install it by yum install mysql-community-server

    Start it with systemctl: systemctl start mysqld

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

    Try first 2, 3 solutions. Error is stil popup & If you can not find /var/lib/mysql/mysql.sock

    find /var/ -name mysql.sock
    

    Check the space available in /var/

    df
    

    If the directory is full remove some unusefull files/directories

    rm /var/cache/*
    

    Probably your issue will sorted now.

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

    If your file my.cnf (usually in the etc folder) is correctly configured with

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

    you can check if mysql is running with the following command:

    mysqladmin -u root -p status
    

    try changing your permission to mysql folder. If you are working locally, you can try:

    sudo chmod -R 777 /var/lib/mysql/
    

    that solved it for me

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