14

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.

2
  • I got same error how i fixed it in linux. stackoverflow.com/a/60557989/7300865
    – Timma
    Mar 6, 2020 at 5:24
  • The catch is you gotta add socket variable under [client] also, not only [mysqld] Either in a global configuration file or ~/.my.cnf
    – Luka
    Aug 2, 2020 at 18:03

7 Answers 7

15

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


[mysqld]
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

0
7

My issue was that multiple mysql processes were running concurrently.

First kill the processes with:

sudo pkill mysql

and

sudo pkill mysqld

restart mysql

sudo service mysql restart

now you should be able to log in

mysql -u root -p
0
5

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_USER=root
MYSQL_PASS=rootpassword
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

2

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.

2

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

0
1

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.

0

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

sudo /etc/init.d/mysql start

1
  • 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.
    – RLF
    Jul 13, 2016 at 21:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.