Our mysql service went offline earlier and when we attempted to restart it we were presented with the following error:

System error 2: No such file or directory ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

We checked the mysql config and it is looking in: datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock

but our mysql.sock file is no longer present in /var/lib/mysql/

We tried 'whereis mysql.sock' and it returned: mysql: /usr/bin/mysql /usr/lib/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

Several help guides suggested running: ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

but /temp/ is empty.

Does anyone know how we might repair this problem please?


The socket is a temporary file which is created when the service starts up, similer to a tcp or udp port, please check your mysql log to see why mysql is not starting.

  • *[root@svr mysql]# tail -f /var/log/mysqld.log thd=(nil) Attempting backtrace. You can use the following information to find out where mysqld died. If you see no messages after this, something went terribly wrong... frame pointer is NULL, did you compile with -fomit-frame-pointer? Aborting backtrace! – Nick Sep 5 '10 at 21:12

Try touch /var/lib/mysql/mysql.sock

It may go ahead and setup the socket as long as the file exists. You might make ownership the mysql user as well.

The location must be writeable and readable my the mysql user. (Your mysql user may be different I think the default is mysql)

chown -R mysql /var/lib/mysql/

A rough mini-tut is here: http://anthologyoi.com/computers/cant-connect-to-local-mysql-server-through-socketerror.html

In addition if the mysqld perocess is running you might want to kill any instances and then try restarting. pidof mysqld should tell you if any instances exist.

Also instead of whereis the command find / -name mysql.sock may be more helpful.

  • The file was created with 644 permissions, but the error remains the same. What command would we use to take ownership of the mysql user please? – Nick Sep 5 '10 at 21:08
  • We applied the chown, checked that no instances were running and the find brought back no results, but it did not work sadly – Nick Sep 5 '10 at 21:19
  • It's a long shot, but you can try chmod 777 /var/lib/mysql/mysql.sock (after running the touch command) just in case your not running under the mysql user. (If it does work you just need to work with ownership/permissions.) Remember to fix permissions after your done troubleshooting. touch /var/lib/mysql/mysql.sock should create a empty file named mysql.sock in /var/lib/mysql/ btw. – Joshua Enfield Sep 5 '10 at 21:21
  • 1
    The same error applies, but it deletes mysql.sock as soon as the mysql service fails to load. – Nick Sep 5 '10 at 21:29

If it's refusing to start, it might need reinstalling to get the files back.
cp -a /var/lib/mysql /root/mysql_backup
for i in $(rpm -qa | grep "mysql"); do echo "Erasing $i"; echo "$i" >> /root/erased_rpms; rpm -e $i; done (the erased_rpms is just in case this has done too much afterwards)
yum install mysql-server

  • How would you then restore the mysql backup afterwards please? – Nick Sep 6 '10 at 11:45
  • Ideally you wouldn't have to, it's a "just in case" backup (I don't believe removing the RPM removes the data but I could be wrong) – James L Sep 6 '10 at 11:57
  • If you did need to, I'd stop MySQL, change the my.cnf to add datadir = /root/mysql_backup (just realised root might be a bad place for it permissions wise, but that could easily be moved) and start MySQL. If your data is there, take the opportunity to do a full mysqldump, remove the datadir, restart MySQL and import the dump. – James L Sep 6 '10 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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