I've been confronted with a specific situation recently, searching through the internet and linux specs did not give a definitive answer. Well, I believe it's not possible but maybe you know the way.

The scenario is as follows

  1. /var/lib/mysql/mysql.sock created by a mysql process on start
  2. /var/lib/mysql/mysql.sock disappears e.g. removed by some external action
  3. ss -lpn | grep mysqld still shows this unix socket

    u_str LISTEN 0 128 /var/lib/mysql/mysqld.sock -786114905 * 0 users:(("mysqld",pid=30220,fd=41))

  4. lsof -p 30220 | grep /var/lib/mysql/mysqld.sock shows a process is bound to it

    mysqld 30220 mysql 41u unix 0xffff8800245603c0 0t0 3508852391 /var/lib/mysql/mysqld.sock

Is it possible to recreate/restore the deleted unix socket file without the parent process restart so that clients can still connect through the this socket file as before the deletion?


  • unix/linux kernel use inode number, if you create one more time, you will get a new inode number, better if you restart the process. – c4f4t0r Jan 15 at 14:01

You can use the old Unix trick to recover a still open, but deleted file. In that case, you did most of the job there:

ss -lpn | grep mysqld 

u_str  LISTEN     0      128    /var/lib/mysql/mysqld.sock -786114905            * 0                   users:(("mysqld",pid=30220,fd=41))

Check the open files from the PID, here, 30220:

# ls -l /proc/30220/fd

lr-x------ 1 mysql mysql 64 janv. 15 19:04 0 -> /dev/null
l-wx------ 1 mysql mysql 64 janv. 15 19:04 1 -> /var/log/mysqld.log
lrwxrwxr-- 1 mysql mysql 64 janv. 15 19:04 2 -> /var/lib/mysql/mysqld.sock (deleted)

Now you can symlink /proc/30220/fd/2 back to an alternate name (you won't be able to restore it to the same name however).

|improve this answer|||||
  • 1
    On Linux, you can create the symlink to have the same name as the original file had (i.e. mysqld.sock). – Lacek Jan 16 at 9:27

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.