How to solve "Can't connect to local MySQL server through socket" error?

  • I kept getting this following error every time I tried to restart MySql. It was working fine before I changed the default data directory.

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

    I know there are other solutions posted by others but none of them worked for me.

    I got same error how i fixed it in linux.

  • Check the folowing

    1. First check if another instance is runnig in the same machine

      ps ax | grep mysql

    2. Then, check if your file my.cnf (probably in /etc/mysql/ folder) is correctly configured with

    datadir = /var/lib/mysql/
    socket = /var/lib/mysql/mysql.sock
    1. Next, you have changed the default data directory, did you gave the right permissions to the new directory now
     chown mysql:mysql -R /var/lib/mysql/*
     chmod 755 -R /var/lib/mysql/*
    1. After changing the permission restart the service and check

      service mysql restart

  • It would appear that the socket file is missing. service mysql stop and service mysql restart depend on the socket file's existence to shutdown.

    You will have to connect to mysql using mysqladmin and TCP/IP to shutdown

    MYSQL_CONN="-h127.0.0.1 -u${MYSQL_USER} -p${MYSQL_PASS} --protocol=tcp -P3306"
    mysqladmin ${MYSQL_CONN} shutdown
    service mysql start

    I have posts about shutdowns like this

  • My issue was that multiple mysql processes were running concurrently.

    First kill the processes with:

    sudo pkill mysql


    sudo pkill mysqld

    restart mysql

    sudo service mysql restart

    now you should be able to log in

    mysql -u root -p
  • Hi i'have just installed zabbix 3.0 and same problem appeared after few hours ago. When i check the zabbix permission in the phpmyadmin I realised there is no permission for user "zabbix" . I gave Grand permission to zabbix and problem solved. This might be helpfull for someone.

  • I was getting the same error as well "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib /mysql/mysql.sock' (111)". I have uninstalled and re-installed MySQl several times and have spent multiple hours troubleshooting the issue. The issue that I notice is when I added the credentials in the my.cnf option file located in /etc/my.cnf as this will cause MySQL issues with starting the services and would throw the error.

    To resolve this, I removed the credentials out of the my.cnf option file in /etc/my.cnf and I create a .my.cnf option file in the home directory. For example /home/username/.my.cnf in Linux (replace username with your username in Linux) and add the credentials in there. No issues after that.

  • I got the same error, but simple reason: system had run out all disk space.

  • Check your mysql service or if you are accessing through ssh try running:

    sudo /etc/init.d/mysql start

    You need to give a little more explanation than just 'do this'. Providing some simple explanation would be a good start. Just edit your post and add the explanation.

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM