网站首页学无止境MySQL

mysql出现“Incorrect key file for table”解决办法

发布时间:2015-01-19 23:00:27编辑:songlin阅读(1043)

    最近在把一个网站从window服务器移到linux服务器上,由于是把mysql 里面的数据直接copy过来的 结果问题来了:Incorrect key file for table。

    1. mysql> select * from test; 
    2.  
    3. ERROR 1034 (HY000): Incorrect key file for table ‘test’; try to repair it 

    首先通过repair table修复:

    1. mysql> repair table test; 
    2.  
    3. +—————+——–+———-+———————————————————+ 
    4.  
    5. Table | Op | Msg_type | Msg_text | 
    6.  
    7. +—————+——–+———-+———————————————————+ 
    8.  
    9. | test.test | repair | Error | Incorrect key file for table ‘test’; try to repair it | 
    10.  
    11. | test.test | repair | error | Corrupt 

    如果还是没用,运行下面命令

    1. mysql> repair table test USE_FRM; 
    2.  
    3. +—————+——–+———-+———————————————————+ 
    4.  
    5. Table | Op | Msg_type | Msg_text | 
    6.  
    7. +—————+——–+———-+———————————————————+ 
    8.  
    9. | test.test | repair | Error |Number of rows changed from 0 to 110423 | 
    10.  
    11. | test.test | repair | status | OK 

    按理应该可以了。

    如果还是没用,则退出mysql,执行如下修复动作:

    1. myisamchk -of /alidata/service/mysql/data/test.MYI 
    2.  
    3. myisamchk -r /alidata/service/mysql/data/test.MYI 
    4.  
    5. myisamchk safe-recover /alidata/service/mysql/data/test.MYI 

    再重启mysql后应该可以正常了。
     

    当然如果你和我一样是所有表都是这个问题 那就用“*”来代替表明

    1. myisamchk -of /alidata/service/mysql/data/*.MYI 
    2.  
    3. myisamchk -r /alidata/service/mysql/data/*.MYI 
    4.  
    5. myisamchk safe-recover /alidata/service/mysql/data/*.MYI