MySQL accidentally deletes the InnoDB data file for restoration

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.