遇到这个问题几个敲命令轻松搞定
1、首先进入mysql命令台:
mysql -u root -p 回车 输入密码
2、查询所有的库
mysql> show databases;
3、进入数据库“eduyun_2015_sp1”是库名
mysql> use eduyun_2015_sp1;
4、check table newabout(newabout–出现错误的表)用来检查出现问题的表的状态,出现错误就正常
5、然后用repair table newabout
6、再用check table newabout 检查一下就ok了
7、ok 搞定
———————
今天测试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)