Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql5.7 uses frm and ibd to recover data

Shulou Source: shulou.com Published: 2022-06-01 04:46:05 11月02日 Update

Mysql5.7 uses frm and ibd to recover data

1. Create a new database with the same name, and create a new table with the same name in it, with arbitrary fields.

-if you have the table structure of the original table, this step can be omitted

Add my.cnf profile to innodb_force_recovery=6

2. Overwrite the backup .frm file over the .frm file of the newly created table, modify the file owner and permissions, and restart the database. At this time, the err file will prompt you that the number of fields in the table structure is inconsistent.

3. Create a table with the same name repeatedly. There are as many fields as prompted, and the field name type is arbitrary.

4. Overwrite the backup .frm file over the .frm file of the newly created table, modify the file owner and permissions, and restart the database; so that the table structure is restored.

5. Rebuild the new table according to the table structure, and specify the ROW_FORMAT attribute of the table, ROW_FORMAT=COMPACT

CREATE TABLE ty (

Id bigint (20) NOT NULL AUTO_INCREMENT COMMENT 'primary key'

Valid int (11) whether DEFAULT'1' COMMENT'is valid 1: valid 0: invalid'

Rel varchar (25) DEFAULT NULL

PRIMARY KEY (id)

) DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT

In this way, the table structure is restored.

6. Restore data

Execute the discard tablespace command in the specified database

Alter table ty discard tablespace

7. Copy the original ibd file, overwrite the newly created table ibd, and modify the permissions

Chown mysql.mysql ty.ibd

8. Import tablespaces

Alter table ty import tablespace

So the whole data is restored.

-End-By-TangYun-2019.10.14-

Tags: File data structure field database permission valid backup space prompt consistent name command done attribute copy time type configuration Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft macOS vpn OPPO Reno