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

How does Vue download non-same-origin files based on URL

Generally speaking, we can have the following two...

How to build Nginx image server with Docker

Preface In general development, images are upload...

A detailed introduction to the basics of Linux scripting

Table of contents 1. Script vim environment 2. Ho...

Detailed explanation of various usages of proxy_pass in nginx

Table of contents Proxy forwarding rules The firs...

Let's talk about my understanding and application of React Context

Table of contents Preface First look at React Con...

In-depth understanding of CSS @font-face performance optimization

This article mainly introduces common strategies ...

Example code for implementing triangles and arrows through CSS borders

1. CSS Box Model The box includes: margin, border...

How to connect Django 2.2 to MySQL database

1. The error information reported when running th...

Specific use of MySQL window functions

Table of contents 1. What is a window function? 1...

Tutorial on compiling and installing MySQL 5.7.17 from source code on Mac

1. Download and unzip to: /Users/xiechunping/Soft...

How to collect Nginx logs using Filebeat

Nginx logs can be used to analyze user address lo...