How can I restore InnoDBibdata files manually deleted by mistake?

Source: Internet
Author: User
In daily work, because I am not familiar with the InnoDB engine, many people in the group have mistakenly deleted InnoDBibdata (data files) and ib_logfile (redolog redo transaction log files ), the result is a cup. For example

In daily work, because I am not familiar with the InnoDB engine, many people in the group have mistakenly deleted InnoDBibdata (data files) and ib_logfile (redolog redo transaction log files ), the result is a cup. For example

In daily work, because I am not familiar with the InnoDB engine, many people in the group have mistakenly deleted InnoDB ibdata and ib_logfile (redo log redo transaction log files ), the result is a cup. If you have master-slave replication and synchronization, it's okay. What if it's a single machine? How to restore?

See the restoration demo for the Hong Kong server below:

1. You can use sysbench to simulate Data Writing, for example:

2. rm-f ib *

3. At this time, I guess you are scared and have a trembling face. If you see this article, your mind will be stable and you will be able to recover.

4. At this time, you will find that the database can still work normally and data can still be written. Remember, do not kill the mysqld process at this time; otherwise, you will only have to skip the building and the gods will not be able to save you.

5. First find the mysqld process pid

  • # Netstat-ntlp | grep mysqld
  • Tcp 0 0 0.0.0.0: 3306 0.0.0.0: * LISTEN 30426/mysqld
  • Here I am 30426

    6. Key Steps

    10, 11, 4, and 9 are the files to be restored.

    7. You can disable the front-end service or execute flush tables with read lock. This step prevents the database from being written for subsequent recovery.

    8. How can I verify that no write operation is performed? Take the following steps for US space. Remember to observe them together.

  • # Refresh the dirty pages to the disk as soon as possible.
  • 9. After the above series of validation work is completed, we can recover. Do you still remember the deleted files we recorded just now?

    Copy these files to the original directory and modify user attributes.

    And modify user attributes

  • # Cd/u2/mysql/data/
  • # Chown mysql: mysql ib *
  • 10. All you can do is restart MySQL.

  • /Etc/init. d/mysql restart
  • How? It's that simple. You can also try it.

    This article is from the "hechun's technical column" blog, the U.S. server, please be sure to keep this source

    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.