MySQL錯(cuò)誤Table xx is marked as crashed and should be repaired
首頁(yè)爆出數(shù)據(jù)庫(kù)錯(cuò)誤
報(bào)錯(cuò)關(guān)鍵信息:Table 'xx_users' is marked as crashed and should be repaired
提示這張表?yè)p壞了,必須修復(fù),登陸服務(wù)器之后,開始修復(fù),以下記錄備忘。
1、嘗試使用myisamchk命令對(duì)所有表索引文件進(jìn)行修復(fù):
myisamchk --safe-recover /var/lib/mysql/test/*.MYI
2、刷新首頁(yè)依然報(bào)錯(cuò),于是登陸MySQL,執(zhí)行 REPAIR TABLE xx_users;
mysql> REPAIR TABLE xx_users;
+-------------------------+--------+----------+-------------------------------------------------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+-------------------------+--------+----------+-------------------------------------------------------------------------------------------------------------+
| xx_xxx.xx_users | repair | error | 1 when fixing table |
| xx_xxx.xx_users | repair | Error | Can't change ownership of the file '/xx_xxx/xx_users.MYD' (Errcode: 1) |
| xx_xxx.xx_users | repair | status | Operation failed |
+-------------------------+--------+----------+-------------------------------------------------------------------------------------------------------------+
3、提示無(wú)法修改擁有著屬性,應(yīng)該是上一步使用myisamchk命令時(shí)文件所屬變成了root了,于是用chown更該擁有者:
chown -R mysql:mysql /xx_xxx/*
4、然后繼續(xù)登陸MySQL執(zhí)行 REPAIR TABLE xx_users; 成功:
刷新首頁(yè)正常
事后總結(jié):一般這個(gè)報(bào)錯(cuò)都是因?yàn)閿?shù)據(jù)庫(kù)表索引文件損壞導(dǎo)致的,發(fā)現(xiàn)這類錯(cuò)誤可以嘗試使用phpMyAdmin的Repair自動(dòng)修復(fù)功能。
如果不行,先將數(shù)據(jù)庫(kù)文件做好備份,然后按照本文的步驟嘗試修復(fù)吧。