MySQL accidentally deletes the InnoDB data file for restoration
Error reproduction:
Use rm-f ib * to delete data files and redo log files. At this time, the mysql process still exists and mysql can still be used normally.
File recovery:
1: Find the process Number of mysqld.
# Netstat-ntpl | grep mysqld
Tcp 0 0 0.0.0.0: 3306 0.0.0.0: * LISTEN 12147/mysqld
2: Use the process number to find the following files.
# Ll/proc/12147/fd | egrep 'ib _ | ibdata'
Lrwx ------ 1 root 64 Jun 18 10->/mydata/ib_logfile1 (deleted)
Lrwx ------ 1 root 64 Jun 18 4->/mydata/ibdata1 (deleted)
Lrwx ------ 1 root 64 Jun 18 09: 23 9->/mydata/ib_logfile0 (deleted)
3: Add a lock so that no write operation is performed on the database.
SQL> flush tables with read lock;
4: Enter the following command to refresh the dirty pages to the disk as soon as possible.
SQL> set global innodb_max_dirty_pages_pct = 0;
5. Check the innodb status information and confirm that the dirty pages have been flushed into the disk. The comparison values are as follows:
6: After confirmation, you can restore the file and copy the deleted files recorded earlier to the original directory.
# Cd/proc/12147/fd
# Cp 10/mydata/ib_logfile1
# Cp 4/mydata/ibdata1
# Cp 9/mydata/ib_logfile0
7: restart the mysqld service.
This article permanently updates the link address: