Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Have a pretty simple problem, I have accidentally deleted /tmp/mysql.sock file

Now I can not use mysqladmin or anything

How can I recreate this file?

Before I asking this question I have looked at related questions, but I could not find info that I needed.

Thank You

share|improve this question
up vote 0 down vote accepted

Are you sure your mysql.sock is inside /tmp/? I think usually this is located in /home/mysql or under the data directory (/var/lib/mysql/). You may as well check if it is still available there.

If it is, rather than restarting the daemon, you can just create a softlink to /tmp:

ln -s /var/lib/mysql/mysql.sock /tmp/
share|improve this answer

Restart mysqld.

/etc/init.d/mysql restart


/sbin/service mysql restart
share|improve this answer
Unfortunately I have installed MySQL from source :( – Daniil Harik Oct 12 '09 at 16:01
How do you start it? You can have an init script even if you install from source. If you don't have one, just killall mysqld and restart it however you normally do. – Josh Oct 12 '09 at 16:02
That gave ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) and mysql: unrecognized service – Magne Oct 9 '14 at 10:01
@Magne Then just try: /etc/init.d/mysql start – Josh Oct 9 '14 at 14:52
I got it working. Since I was on CentOS, I had to write mysqld instead of mysql. So it became: /etc/init.d/mysqld stop and /etc/init.d/mysqld start – Magne Oct 9 '14 at 15:23

Just restart your MySQL daemon.

share|improve this answer

You can't recreate it since it's a named socket. As others have said, you must restart mysqld.

share|improve this answer

edited my.cnf to reflect this (replacing "socket = /var/lib/mysql/mysql.sock" with "socket = /opt/lampp/var/mysql/mysql.sock")

share|improve this answer
He didn't move it, he deleted the socket. he just needs MySQL to recreate it. – Josh Oct 12 '09 at 19:12

You may see this even after starting mysqld because the process is still setting up. I've seen it with Innodb taking several minutes, can be even longer, to restore, and during that time, there will be no socket file. Check your Mysql error log to see if there's activity like this taking place (tail -f /var/log/mysql.err).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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