MyISAM recovery method After the loss of the. frm file for the table

Source: Internet
Author: User

Recovery method for MyISAM table when the. frm file is missing:

1, create the experimental MyISAM table T1, and insert 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 for the T1 table

[Email protected] gusha]# Cd/var/lib/mysql/gusha

[[email protected] gusha]# ls

db.opt t1. MYI t1.frm t1. MYD

[Email protected] gusha]# RM-RF t1.frm

At this time in the Gusha library has not been queried the T1 table:

Mysql> Show tables;

Empty Set (0.00 sec)

You can also query the contents of the T1 table because there is a cache, 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, to restore, the Gusha library corresponding to the folder in the T1. MyD and T1.myi files are moved to another folder:

[Email protected] gusha]# mv T1. my*/var/lib/backup/

[[email protected] gusha]# ls

Db.opt

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

mysql> CREATE TABLE t1 (id int) Engine=myisam;

Query OK, 0 rows Affected (0.00 sec)

Put T1. MyD and T1.myi files move to the folder corresponding to the Gusha library:

[Email protected] gusha]# mv/var/lib/backup/t1. my*.

Mv:overwrite './t1. MYD '? Y

Mv:overwrite './t1. MYI '? Y

MySQL will automatically fix the T1 table at this time

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 fix, 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)

The MyISAM table T1.frm lost and returned.

For more exciting MySQL content please follow me:
650) this.width=650; "Src=" http://qr.liantu.com/api.php?bg=ffffff&fg=000000&gc=000000&el=L&text= http%3a%2f%2fwap.wyzc.com%2freg%2f%3ftg%3d3006123630 "style=" Border:0px;color:rgb (229,51,51); font-family: ' Microsoft Yahei ', ' Microsoft Jas Black '; Font-size:32px;line-height:48px;white-space:pre-wrap;background-color:rgb (255,255,255); " alt= "Api.php?bg=ffffff&fg=000000&gc=000000&el"/>

MyISAM recovery method After the loss of the. frm file for the table

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.