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

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

    This is a problem if you are running out of disk space. Solution is to free some space from the HDD.

    Please read more to have the explanation :

    If you are running MySQL at LINUX check the free space of HDD with the command disk free :

     df 
    

    if you are getting something like that :

    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/sda2              5162828   4902260         0 100% /
    udev                    156676        84    156592   1% /dev
    /dev/sda3              3107124     70844   2878444   3% /home
    

    Then this is the problem and now you have the solution!

    Since mysql.sock wants to be created at the mysql folder which is almost always under the root folder could not achieve it because lack of space.

    If you are periodicaly give the ls command under the mysql directory (at openSUSE 11.1 is at /var/lib/mysql) you will get something like :

    hostname:/var/lib/mysql #
    .protected  IT     files        ibdata1             mysqld.log  systemtemp
    .tmp        NEWS   greekDB      mysql               mysqld.pid  test
    ARXEIO      TEMP1  ib_logfile0  mysql.sock          polis
    DATING      deisi  ib_logfile1  mysql_upgrade_info  restore
    

    The mysql.sock file appearing and disappearing often (you must to try allot with the ls to hit a instance with the mysql.sock file on folder).

    This caused by not enough disk space.

    I hope that i will help some people!!!! Thanks!

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

    It worked for me with the following changes

    Whatever path for socket is mentioned in [mysqld] and same in [client] in my.cnf and restart mysql

    [mysqld] socket=/var/lib/mysql/mysql.sock

    [client] socket=/var/lib/mysql/mysql.sock

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

    If you are in the shell of sf.net, try:

    mysql --host=mysql-{LETTER} --user={LETTER}{GROUP ID}admin -p
    

    Change {LETTER} and {GROUP ID} as shown in your MySQL Database of project admin profile.

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

    The MySQL server is not running, or that is not the location of its socket file (check my.cnf).

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

    If you are on a recent RHEL, you may need to start mariadb (an open source mysql db) instead of the mysql db:

    yum remove mysql
    yum -y install mariadb-server mariadb
    service mariadb start
    

    You should then be able to access mysql in the usual fashion:

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

    Note that while mysql reads the info of the location of the socketfile from the my.cnf file, the mysql_secure_installation program seems to not do that correctly at times.

    So if you are like me and shuffle things around at installationtime you might get into the situation where you can connect to the database with mysql just fine, but the thing can not be secured (not using that script anyway).

    To fix this the suggestion from sreddy works well: make a softlink from where the script would expect the socket to where it actually is. Example:

    ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
    

    (I use /tmp/ as a default location for sockets)

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