zabbix登陸頁面報錯,提示mysql無法連接,登陸服務器后,查看mysql日誌,ps –ef mysql,發現服務還在,查看mysql日誌,日誌路徑如下,如果服務不在了請find / -name my.cnf查看配置文件路徑配置,查看日誌路徑
查看日誌,發現一直重啟,查看具體報錯
由上可以看到數據庫zabbix的history表的二級索引損壞
修復方法
1.因為數據庫一直因為報錯在重啟,所以先在my.cnf數據庫配置文件增加一列參數,使其不掃描壞的表
2.重啟數據庫systemctl restart mariadb.service。
3.成功重啟數據庫后執行命令修復壞的表,創建一個跟損壞表一樣的表:
Show create table history(查看創建表的SQL語句,然後按照語句更改表名)
CREATE TABLE history_bake
(
itemid
bigint(20) unsigned NOT NULL,
clock
int(11) NOT NULL DEFAULT ‘0’,
value
double(16,4) NOT NULL DEFAULT ‘0.0000’,
ns
int(11) NOT NULL DEFAULT ‘0’,
KEY history_1
(itemid
,clock
)
) ENGINE=myisam DEFAULT CHARSET=utf8 COLLATE=utf8_bin;()
4.將數據從原表複製到新建的表
insert into history_bake select * from history;
5.複製完成后刪除舊的表
Drop table history;
6.將my.cnf配置文件的innodb_force_recovery =1註釋掉,重啟mysql
7.將history_bake表改名成history(rename table history_bake to history;)
8.將history表的引擎改成innodb(alter table history engine = innodb;)