Get the App
SLTechnology News&Howtos  ›  Database  › 

How to recover the .frm file of MyISAM table after it is lost

Shulou Source: shulou.com Published: 2022-05-31 15:59:56 09月23日 Update

This article mainly introduces the MyISAM table after the loss of .frm file how to recover, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Recovery method after missing .frm file of MyISAM table:

1. Create the experimental MyISAM table T1, and insert the data:

Mysql > create table T1 (id int) engine=myisam

Query OK, 0 rows affected (0.01 sec)

Mysql > insert into T1 values (1), (2), (3), (4), (5), (6), (7), (8)

Query OK, 8 rows affected (0.00 sec)

Records: 8 Duplicates: 0 Warnings: 0

2. Delete the .frm file of the T1 table

[root@localhost gusha] # cd / var/lib/mysql/gusha

[root@localhost gusha] # ls

Db.opt t1.MYI t1.frm t1.MYD

[root@localhost gusha] # rm-rf t1.frm

At this point, the T1 table cannot be queried in the gusha library:

Mysql > show tables

Empty set (0.00 sec)

You can also query the contents of the T1 table because there is a cache, so clear the cache:

Mysql > select * from T1

+-+

| | id |

+-+

| | 1 |

| | 2 |

| | 3 |

| | 4 |

| | 5 |

| | 6 |

| | 7 |

| | 8 |

+-+

8 rows in set (0.00 sec)

Mysql > flush tables

Query OK, 0 rows affected (0.00 sec)

Mysql > select * from T1

ERROR 1146 (42S02): Table 'gusha.t1' doesn't exist

3. Restore and move the t1.MYD and t1.MYI files in the folder corresponding to the gusha library to another folder:

[root@localhost gusha] # mv t1.MY* / var/lib/backup/

[root@localhost gusha] # ls

Db.opt

Recreate a T1 table in the gusha library with the same structure as the original T1 table:

Mysql > create table T1 (id int) engine=myisam

Query OK, 0 rows affected (0.00 sec)

Move the t1.MYD and t1.MYI files to the folder corresponding to the gusha library:

[root@localhost gusha] # mv / var/lib/backup/t1.MY*.

Mv: overwrite `. / t1.MYDuring? Y

Mv: overwrite `. / t1.MYIQUE? Y

At this point, MySQL will automatically repair the T1 table.

Mysql > select * from T1

+-+

| | id |

+-+

| | 1 |

| | 2 |

| | 3 |

| | 4 |

| | 5 |

| | 6 |

| | 7 |

| | 8 |

+-+

8 rows in set (0.00 sec)

If there is no automatic repair, execute the following command to fix it:

Mysql > repair table T1

+-+

| | Table | Op | Msg_type | Msg_text | |

+-+

| | gusha.t1 | repair | status | OK | |

+-+

1 row in set (0.00 sec)

Thank you for reading this article carefully. I hope the article "how to recover after the loss of the .frm file of the MyISAM table" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Files articles folders caches libraries queries moves values interests content at the same time commands data methods more friends knowledge structure editing industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Docker macOS Huawei Shulou Information