Heim  >  Artikel  >  Datenbank  >  mysql中Incorrect key file for table: Try to repair it

mysql中Incorrect key file for table: Try to repair it

WBOY
WBOYOriginal
2016-06-07 17:52:373839Durchsuche

在windows系统中有时会碰到mysql中Incorrect key file for table: Try to repair it提示,导致mysql 表毁坏的常见原因:1、 服务器突然断电导致数据文件损坏。2、 强制关机,没有先关闭mysql 服务等。

损坏的症状

一个损坏的表的典型症状如下:
1 、当在从表中选择数据之时,你得到如下错误:Incorrect key file for table: '...'. Try to repair it
2 、查询不能在表中找到行或返回不完全的数据。
3 、Error: Table 'p' is marked as crashed and should be repaired 。
4 、打开表失败: Can’t open file: ‘×××.MYI’ (errno: 145) 。


MySQL 表损坏的修复

MyISAM 表可以采用以下步骤进行修复 :

1、  使用 reapair table 或myisamchk 来修复。
 用phpmyadmin修复表后悲具了,提示“marked as crashed and last (automatic) repair failed "。查了一相关资料后得知用myisamchk工具可以修复表。
 myisamchk.exe在MySQLbin目录下,如果该目录下没有请下载本文附件myisamchk.rar。

要检查一个表的错误,只需要运行myisamchk(在MySQL的bin目录下)并提供文件的位置和表名,或者是表的索引文件名:

 代码如下 复制代码

myisamchk /usr/local/mysql/var/dbName/tblName
myisamchk /usr/local/mysql/var/dbName/tblName.MYI


上面的两个命令都可以执行对指定表的检查。要检查数据库中所有的表,可以使用通配符

修复步骤:

 1)修复前将mysql服务停止。
 2)打开命令行方式,然后进入到mysql的/bin目录。
 3)执行myisamchk --recover  数据库所在路径/*.MYI。   注:提示后面不要跟随;号

不过需要注意的是,Myisamchk工具并不是万能的。对于一些极端性的损坏,如表格描述文件损坏,这个工具就没有用武之地了。为此数据库管理员还是需要最好数据库日常的备份工作

利用phpmyadmin修改

在phpmyadmin中找到出现问题的表的数据库,然后进入找到出问题的表,再点击下面的修复表即可快速实现解决这个问题。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn