InnoDB type MySql restore table structure and data

InnoDB type MySql restore table structure and data

Prerequisite: Save the .frm and .ibd files that need to restore the database

Condition: InnoDB type

Recover table structure

1. Create a new database - create a new table with the same table name and number of columns as the database to be restored
2. Stop the mysql server service mysql stop ,
3. Add innodb_force_recovery = 6 in /usr/local/mysql/my.cnf
4. Overwrite the .frm format file of the table to be restored with the .frm format file in the /usr/local/mysql/data/ database
5. Start the mysql server service mysql start
6. Stop the database service service mysql stop and comment out innodb_force_recovery = 6 in my.cnf
7. Start the mysql server service mysql start

Recover Data

1. Restore the table structure first
2. Execute alter table `user` discard tablespace; After execution, the user.ibd file in the database directory disappears.
3. Put your backed up ibd to the disappeared user.ibd file
4. Add permissions to this file: chown -R mysql:mysql data The owner is mysql
5. Execute alter table `user` import tablespace; After execution, the table data can be read, but some information in the system table, such as the number of table rows, will be lost.

Note: If you encounter a foreign key constraint, add SET FOREIGN_KEY_CHECKS = 0 before the statement; remember to change it to 1 after completion

You may also be interested in:
  • Performance comparison test of MySQL's two table storage structures MyISAM and InnoDB
  • Detailed explanation of the index and storage structure of the MySQL InnoDB engine
  • Detailed explanation of MySQL Innodb storage structure and storage of Null values
  • Detailed explanation of the data page structure of MySQL's InnoDB storage engine
  • MySQL InnoDB memory structure details

<<:  JS ES6 asynchronous solution

>>:  How to configure pseudo-static and client-adaptive Nginx

Recommend

A brief analysis of SQL examples for finding uncommitted transactions in MySQL

A long time ago, I summarized a blog post titled ...

jQuery implements sliding tab

This article example shares the specific code of ...

Introduction to user management under Linux system

Table of contents 1. The significance of users an...

HTML Table Tag Tutorial (47): Nested Tables

<br />In the page, typesetting is achieved b...

Example of implementing login effect with vue ElementUI's from form

Table of contents 1. Build basic styles through E...

Summary of Textarea line break issues in HTML

Recently, I encountered a problem of whether the d...

Introduction to the use of this in HTML tags

For example: Copy code The code is as follows: <...

Analysis of the methods of visual structure layout design for children's websites

1. Warm and gentle Related address: http://www.web...

JavaScript file loading and blocking issues: performance optimization case study

Let me start with a question: When writing an HTM...

How to achieve the maximum number of connections in mysql

Table of contents What is the reason for the sudd...

Detailed tutorial on installing Docker and nvidia-docker on Ubuntu 16.04

Table of contents Docker Installation Nvidia-dock...