How to restore the table structure of MySQL InnoDB

Source: Internet
Author: User

What is the restoration method for MySQL InnoDB table structure? The following describes in detail the restoration steps of the MySQL InnoDB table structure. If you are interested in this, take a look.

MySQL InnoDB Table Structure Restoration:

Assume that the MYSQL database has crashed. Currently, only frm files of the corresponding table are available. As we all know, frm files cannot be viewed in the text editor. If they are not restored, they are basically useless to us. In this example, we assume that the file is test_innodb.frm.

The table creation script is as follows:

 
 
  1. mysql> create table test_innodb  
  2.  
  3.     -> (A int(11) default NULL,  
  4.     -> B varchar(30) default NULL,  
  5.     -> C date default NULL) engine=innodb;  
  6. Query OK, 0 rows affected (0.05 sec)  
  7.  

Recovery Method Introduction (process ):

1. Create a database in a new normal MYSQL environment, such as aa.

2. Create a data table test_innodb with the same name under the aa database. The table structure is random. Here there is only one id field. The operation procedure is as follows:

 
 
  1. mysql> create table test_innodb (id bigint not null)engine=InnoDB;  
  2. Query OK, 0 rows affected (0.09 sec)  
  3.  
  4. mysql> show tables;  
  5. +--------------+  
  6. | Tables_in_aa |  
  7. +--------------+  
  8. | test_innodb |  
  9. +--------------+  
  10. 2 rows in set (0.00 sec)  
  11.  
  12. mysql> desc test_innodb;  
  13. +-------+------------+------+-----+---------+-------+  
  14. | Field | Type       | Null | Key | Default | Extra |  
  15. +-------+------------+------+-----+---------+-------+  
  16. | id    | bigint(20) | NO   |     | NULL    |       |  
  17. +-------+------------+------+-----+---------+-------+  
  18. 1 row in set (0.00 sec)  
  19.  

3. Stop the mysql server, copy the test_innodb.frm file left after the system crash to the data directory aa of the new normal database, and overwrite the frm file with the same name on the lower side:

4. Restart the MYSQL service.

5. test whether the restoration is successful. log on to the aa database and run the desc command to test the restoration:

 
 
  1. mysql> desc test_innodb;  
  2. +-------+-------------+------+-----+---------+-------+  
  3. | Field | Type        | Null | Key | Default | Extra |  
  4. +-------+-------------+------+-----+---------+-------+  
  5. | A     | int(11)     | YES |     | NULL    |       |  
  6. | B     | varchar(30) | YES |     | NULL    |       |  
  7. | C     | date        | YES |     | NULL    |       |  
  8. +-------+-------------+------+-----+---------+-------+  
  9. 3 rows in set (0.01 sec)  
  10.  

OK. The table structure has been restored.

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.