今天查询mysql的时候,报这样的错误,Incorrect key file for table './piaoyun/hello.MYI'; try to repair it. mysql表损坏的情况是很少见的,下面的方法适用于myisam,其他存储引擎,不知道能不能这样修复。

1,myisamchk修改表。首先先cd切换到出错数据库的表名所在的目录下

[root@localhost piaoyun]# myisamchk -of ./hello.MYI     //修复第一步
- recovering (with keycache) MyISAM-table './hello.MYI'
Data records: 12597637
Found block that points outside data file at 1630252996
Data records: 12597456
[root@localhost piaoyun]# myisamchk -r ./hello.MYI     //修复第二步
- recovering (with sort) MyISAM-table './hello.MYI'
Data records: 12597456
- Fixing index 1
[root@localhost piaoyun]# myisamchk ./hello.MYI     //修复第三步

Checking MyISAM file: ./hello.MYI
Data records: 12597456   Deleted blocks:       0
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check record links

myisamchk带的参数,可以用man看一下。操作后重新启动一下数据库。

[root@localhost piaoyun]# /etc/init.d/mysqld restart

这样操作后,还是有问题,会报 #145 - Table "XXXXX" is marked as crashed and should be repaired。如下图:
myisamchk
myisamchk 修复表后报的错误

2,命令行下repair修复表

mysql> repair table hello;  //hello是表名

如下图
repair_table
到这儿,myisam表损坏就修复好了。

 

暂无评论