Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use lsof to recover mistakenly deleted mysql database files

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following mainly brings you to use lsof to recover mistakenly deleted mysql database files. I hope these contents can bring you practical use, which is also the main purpose of this article for my editor to use lsof to recover mistakenly deleted mysql database files. All right, don't talk too much nonsense, let's just read the following.

After mistakenly deleting database files, please do not restart mysqld!

Rm / data/mysql/test/test2.ibdlsof | grep test2.ibdmysqld 93384 93483 mysql 21uW REG 8 grep test2.ibdmysqld 3 98304 33578386 / data/mysql/test/test2.ibd (deleted)

The PID is 93384 and the file identifier is 21

Cat / proc/93384/fd/21 > / data/mysql/test/test2.ibd

Prompt to restart the database:

Starting MySQL.. ERROR! The server quit without updating PID file (/ data/mysql/mysql.pid).

Reason: the user and user group of ll / data/mysql/test/test2.ibd are root

Solution: chown mysql:mysql / data/mysql/test/test2.ibd

Restart the database successfully

Principle:

When a process opens a file, it still exists on disk as long as the process keeps the file open, 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 provided to it when the file is opened. Apart from the process, this file is not visible because its corresponding directory Inode has been deleted.

In the / proc directory, it contains various files that reflect the kernel and process tree. The / proc directory mounts an area mapped in memory, so these files and directories do not exist on disk, so when we read and write to these files, we are actually getting the relevant information from memory. Most of the lsof-related information is stored in a directory named after the process's PID, that is, / proc/1234 contains information about processes with a PID of 1234. There are various files in each process directory that allow applications to simply understand the memory space of the process, a list of file descriptors, 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 the process's file descriptor and related file name and other information. That is, we can find information about the file by accessing the process's file descriptor.

When a file in the system is accidentally deleted, as long as there are processes in the system accessing the file, we can restore the contents of the file from the / proc directory through lsof.

For the above about the use of lsof to recover mistakenly deleted mysql database files, we do not think it is very helpful. If you need to know more, please continue to follow our industry information. I'm sure you'll like it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report