今天测试mysql,发现一个表出现了以下报错
ERROR 1194 (HY000): Table 't1' is marked as crashed and should be repaired
在网上搜有些说需要通下面方法进行修复
[root@localhost data]# myisamchk -f ./test2/*.MYI
Checking MyISAM file: ./test2/t1.MYI
Data records: 24926 Deleted blocks: 0
- check file-size
myisamchk: error: Size of datafile is: 73 Should be: 174482
- recovering (with keycache) MyISAM-table './test2/t1.MYI'
Data records: 24926
Data records: 5
---------
Checking MyISAM file: ./test2/t2.MYI
Data records: 482688 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
---------
Checking MyISAM file: ./test2/t4.MYI
Data records: 482688 Deleted blocks: 0
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
---------
Checking MyISAM file: ./test2/t5.MYI
Data records: 482688 Deleted blocks: 0
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check record links
然后在mysql 里使用repair中进行修复,成功。
mysql> repair table cmxt.cm_user_pref;
+-------------------+--------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+-------------------+--------+----------+----------+
| cmxt.cm_user_pref | repair | status | OK |
+-------------------+--------+----------+----------+
后来经过实验发现
首先检查check table t1
mysql> check table t1;
+----------+-------+----------+---------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+----------+-------+----------+---------------------------------------------------+
| test2.t1 | check | error | Size of datafile is: 73 Should be: 174482 |
| test2.t1 | check | error | Corrupt |
+----------+-------+----------+---------------------------------------------------+
2 rows in set (0.00 sec)
然后再使用myisamchk来修复
[root@localhost mysql]# myisamchk -f ./data/test2/t1.MYI
Checking MyISAM file: ./data/test2/t1.MYI
Data records: 24926 Deleted blocks: 0
myisamchk: warning: Table is marked as crashed
- check file-size
myisamchk: error: Size of datafile is: 73 Should be: 174482
- recovering (with keycache) MyISAM-table './data/test2/t1.MYI'
Data records: 24926
Data records: 5
然后再查看t1表
mysql> select * from t1;
+-------------+
| str_number |
+-------------+
| NULL |
| NULL |
| -1774844896 |
| NULL |
| NULL |
+-------------+
5 rows in set (0.00 sec)