MyISAM如果损坏了修复方法是比较简单了我们只要使用check table命令就可以了,下面我们来看一篇关于修复MySQL的MyISAM表命令check table用法,具体如下所示。
MySQL日志文件里出现以下错误,MySQL表通常不会发生crash情况,一般是在更新数据库时MySQL停止会导致。
CHECK TABLE语法
CHECK TABLE tbl_name[,tbl_name] ... [option] ...
option= {QUICK | FAST | MEDIUM | EXTENDED | CHANGED}
检查一个或多个表是否有错误。CHECK TABLE对MyISAM和InnoDB表有作用。对于MyISAM表,关键字统计数据被更新。
CHECK TABLE也可以检查视图是否有错误,比如在视图定义中被引用的表已不存在。
CHECK TABLE语句会返回一个含有以下列的表:
[Warning] Checking table: './数据库名/表名'
[ERROR] mysqld: Table './数据库名/表名' is marked as crashed and should be repaired
确认错误使用「check table 表名;」命令。
代码如下 | 复制代码 |
mysql> check table 表名 quick; ------------------ ------- ---------- ---------------------------------------------------------- | Table | Op | Msg_type | Msg_text | ------------------ ------- ---------- ---------------------------------------------------------- | DB.表名 | check | warning | Table is marked as crashed and last repair failed | | DB.表名 | check | warning | 1 client is using or hasn't closed the table properly | | DB.表名| check | error | Size of datafile is: 268414976 Should be: 268871480 | | DB.表名 | check | error | Corrupt | ------------------ ------- ---------- ---------------------------------------------------------- |
从以上结果可以看出MySQL数据库出现了损坏。
修复时使用「repair table 表名;」命令,需要注意的是repair table命令只能用于MyISAM表。
代码如下 | 复制代码 |
mysql> repair table 表名; --------------- -------- ---------- -------------------------------------------------------- | Table | Op | Msg_type | Msg_text | --------------- -------- ---------- -------------------------------------------------------- | DB.表名 | repair | info | Found block that points outside data file at 268414940 | | DB.表名 | repair | warning | Number of rows changed from 4377692 to 4370359 | | DB.表名 | repair | status | OK | --------------- -------- ---------- -------------------------------------------------------- |
再次执行check table命令。
代码如下 | 复制代码 |
mysql> check table 表名 quick; --------------- ------- ---------- ---------- | Table | Op | Msg_type | Msg_text | --------------- ------- ---------- ---------- | DB.表名 | check | status | OK | --------------- ------- ---------- ---------- |