Do not restart mysqld! after you delete the database files by mistake
rm/data/mysql/test/test2.ibdlsof | grep test2.ibdmysqld 93384 93483 mysql 21uW REG 8,3 98304 33578386/data/mysql/test/test2. IBD (Deleted)
PID 93384 file identifier is 21
CAT/PROC/93384/FD/21 >/data/mysql/test/test2.ibd
To restart the database prompt:
Starting MySQL. error! The server quit without updating PID file (/data/mysql/mysql.pid).
Cause: LL/DATA/MYSQL/TEST/TEST2.IBD user and user group are root
Solution: Chown MYSQL:MYSQL/DATA/MYSQL/TEST/TEST2.IBD
Restart database Successful
Principle:
When a process opens a file, it remains on disk as long as the process remains open for that file, even if it is deleted. This means that the process does not know that the file has been deleted, and it can still read and write to the file descriptor that was provided to it when the file was opened. In addition to this process, this file is not visible because its corresponding directory index node has been deleted.
in the/proc directory, it contains various files that reflect the kernel and the process tree. The/proc directory mounts an area that is mapped in memory, so these files and directories do not exist on disk, so when we read and write these files, we actually get the relevant information from memory. Most of the information related to lsof is stored in a directory named after the PID of the process, that is,/proc/1234 contains information about the process with PID 1234. There are various files in each process directory that allow the application to simply understand the process's memory space, file description list characters, symbolic links to files on disk, and other system information. The LSOF program uses this information and other information about the internal state of the kernel to produce its output. So lsof can display information such as the file descriptor of the process and the associated filename. That is, we can find information about the file by accessing the file descriptor of the process.
when a file in the system is accidentally deleted, as long as there are processes in the system that are accessing the file, we can recover the contents of the file from the/proc directory by lsof.
Delete MySQL database files by mistake, use lsof back recovery