1. 程式人生 > 實用技巧 >【MySQL Errors】Table 'xxx' is marked as crashed and should be repaired 的解決方案

【MySQL Errors】Table 'xxx' is marked as crashed and should be repaired 的解決方案

現象描述

訪問 Zabbix Web,出現如下錯誤提示:

•    Error in query [SELECT * FROM history_uint h WHERE h.itemid='25067' ORDER BY h.clock DESC LIMIT 1 OFFSET 0] [Table './zabbix/history_uint' is marked as crashed and should be repaired]
•    Error in query [SELECT * FROM history_uint h WHERE h.itemid='26280
' ORDER BY h.clock DESC LIMIT 1 OFFSET 0] [Table './zabbix/history_uint' is marked as crashed and should be repaired] • Error in query [SELECT * FROM history_uint h WHERE h.itemid='26286' ORDER BY h.clock DESC LIMIT 1 OFFSET 0] [Table './zabbix/history_uint' is marked as crashed and should be repaired]

解決辦法

1、首先進入mysql命令臺:
mysql -u root -p
回車,然後輸入密碼

2、查詢所有的庫
mysql> show databases;

3、進入資料庫“zabbix”是庫名
mysql> use zabbix;

4、檢查表
check table history_uint;
(history_uint :出現錯誤的表)用來檢查出現問題的表的狀態,出現錯誤就正常。

mysql> check table history_uint;
+---------------------+-------+----------+-------------------------------------------------------+
| Table | Op | Msg_type | Msg_text | +---------------------+-------+----------+-------------------------------------------------------+ | zabbix.history_uint | check | warning | Table is marked as crashed | | zabbix.history_uint | check | warning | 1 client is using or hasn't closed the table properly | | zabbix.history_uint | check | error | record delete-link-chain corrupted | | zabbix.history_uint | check | error | Corrupt | +---------------------+-------+----------+-------------------------------------------------------+ 4 rows in set (2 min 48.75 sec)

5、修復表
repair table history_uint;

mysql> repair table history_uint;
+---------------------+--------+----------+--------------------------------------------------+
| Table               | Op     | Msg_type | Msg_text                                         |
+---------------------+--------+----------+--------------------------------------------------+
| zabbix.history_uint | repair | warning  | Number of rows changed from 28813609 to 28843608 |
| zabbix.history_uint | repair | status   | OK                                               |
+---------------------+--------+----------+--------------------------------------------------+
2 rows in set (9 min 12.42 sec)

6、再次檢查表。
check table history_uint;

mysql> check table history_uint; 
+---------------------+-------+----------+----------+
| Table               | Op    | Msg_type | Msg_text |
+---------------------+-------+----------+----------+
| zabbix.history_uint | check | status   | OK       |
+---------------------+-------+----------+----------+
1 row in set (13.57 sec)

7、ok 搞定。