前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MySQL错误修复记录:Table xx is marked as crashed and should be repaired

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

作者头像
张戈
发布2018-03-21 15:03:13
2.2K0
发布2018-03-21 15:03:13
举报
文章被收录于专栏:张戈的专栏张戈的专栏

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

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

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 50 ) [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

代码语言:javascript
复制
- 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;

代码语言:javascript
复制
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 更该拥有者:

代码语言:javascript
复制
chown -R mysql:mysql /HIDE_songsong/*

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

代码语言:javascript
复制
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>

在刷新网站,已经正常:

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

事后总结:一般这个报错都是因为数据库表索引文件损坏导致的,发现这类错误可以尝试使用 phpMyAdmin 的 Repair 自动修复功能。如果不行,先将数据库文件做好备份,然后按照本文的步骤尝试修复吧。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016年05月17日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档