MySQL错误修复记录:Table xx is marked as crashed and should be repaired

  • 时间:
  • 浏览:2
  • 来源:QQ猎鹰乐园_提供QQ思维国际技术_小磊资源网资讯

昨晚入睡后,收到松哥的QQ消息,说松松商城打开报错,于是手机QQ上打开了首页地址,发现有如下报错:

MySQL server error report:Array ( [0] => Array ( [message] => MySQL Query Error ) [1] => Array ( [sql] => SELECT u.user_name, og.goods_number, oi.add_time, IF(oi.order_status IN (2, 3, 4), 0, 1) AS order_status FROM `hide_songsong`.`ecs_order_info` AS oi LEFT JOIN `hide_songsong`.`ecs_users` AS u ON oi.user_id = u.user_id, `hide_songsong`.`ecs_order_goods` AS og WHERE oi.order_id = og.order_id AND og.goods_id = 213 ORDER BY oi.add_time DESC LIMIT 80 ) [2] => Array ( [error] => Table 'ecs_users' is marked as crashed and should be repaired ) [3] => Array ( [errno] => 1194 ) )

关键报错信息:

Table ‘ecs_users’ is marked as crashed and should be repaired

提示这张表损坏了,须要修复,登陆服务器事先,结速了了修复,以下记录备忘。

1、尝试使用myisamchk命令对所有表索引文件进行修复:

myisamchk –safe-recover /path/to/*.MYI

- recovering (with sort) MyISAM-table 'ecs_users.MYI'
Data records: 2593
- Fixing index 1
- Fixing index 2
- Fixing index 3
- Fixing index 4
- Fixing index 5
*******

2、刷新首页依然报错,于是登陆MySQL,执行 REPAIR TABLE ecs_users;

mysql> REPAIR TABLE ecs_users;
+-------------------------+--------+----------+-------------------------------------------------------------------------------------------------------------+
| Table                   | Op     | Msg_type | Msg_text                                                                                                    |
+-------------------------+--------+----------+-------------------------------------------------------------------------------------------------------------+
| hide_songsong.ecs_users | repair | error    | 1 when fixing table                                                                                         |
| hide_songsong.ecs_users | repair | Error    | Can't change ownership of the file '/HIDE_songsong/ecs_users.MYD' (Errcode: 1) |
| hide_songsong.ecs_users | repair | status   | Operation failed                                                                                            |
+-------------------------+--------+----------+-------------------------------------------------------------------------------------------------------------+
3 rows in set (0.02 sec)

3、提示无法修改拥有着属性,应该是上一步使用myisamchk命令时文件所属变成了root了,于是用chown更该拥有者:

chown -R mysql:mysql /HIDE_songsong/*

4、回会 继续登陆MySQL执行 REPAIR TABLE ecs_users;  成功:

mysql> use hide_songsong;
Database changed
mysql> REPAIR TABLE ecs_users;
+-------------------------+--------+----------+----------+
| Table                   | Op     | Msg_type | Msg_text |
+-------------------------+--------+----------+----------+
| hide_songsong.ecs_users | repair | status   | OK       |
+-------------------------+--------+----------+----------+
1 row in set (0.02 sec)

mysql>

在刷新网站,肯能正常:

事后总结:一般你这名报错都是肯能数据库表索引文件损坏意味着着 的,发现类似于错误可不须要尝试使用phpMyAdmin的Repair自动修复功能。肯能不行,先将数据库文件做好备份,回会 按照本文的步骤尝试修复吧。