MYISAM索引文件损坏的修复方法
作者: 丹臣, 出处:blog, 责任编辑: 李书琴,
2008-07-11 10:26
使用MYISAM存储引擎,当创建一个表时,会出现三个文件:数据文件MYD,索引文件MYI,格式文件frm。当索引文件损坏时或者丢失时,可以用如下的方法进行修复。本文介绍了实验过程。
使用格式化文件frm重新创建索引文件
mysql> repair table message_ignore USE_FRM; +-----------------------+--------+----------+----------+ | Table | Op | Msg_type | Msg_text | +-----------------------+--------+----------+----------+ | notify.message_ignore | repair | status | OK | +-----------------------+--------+----------+----------+ 1 row in set (0.02 sec) mysql> mysql> check table message_ignore; +-----------------------+-------+----------+----------+ | Table | Op | Msg_type | Msg_text | +-----------------------+-------+----------+----------+ | notify.message_ignore | check | status | OK | +-----------------------+-------+----------+----------+ 1 row in set (0.02 sec) |
修复后,数据可以正常查询
mysql> select * from message_ignore limit 1; Empty set (0.00 sec) |
如果是格式化文件frm损坏,可以从slave拷贝过来即可,或者从备份中恢复。
附录,在哪些情况下,myisam存储引擎的表容易损坏:
14.1.4.1. Corrupted MyISAM Tables
Even though the MyISAM table format is very reliable (all changes to a table made by an SQL statement are written before the statement returns), you can still get corrupted tables if any of the following events occur:
- The mysqld process is killed in the middle of a write.
- An unexpected computer shutdown occurs (for example, the computer is turned off).
- Hardware failures.
- You are using an external program (such as myisamchk) to modify a table that is being modified by the server at the same time.
- A software bug in the MySQL or MyISAM code.

