1.背景
一台db异常重启后被切换为从库,过了一段时间后,再用pt工具做数据校验时,这台db主从断开了
错误日志:
Last_SQL_Error: Error 'Table 'game_daily_life_20220528' is marked as crashed and should be repaired' on query.
Default database: 'statisticdb'.
Query: 'REPLACE INTO `test1`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT 'statisticdb', 'game_daily_life_20220528', '9', 'PRIMARY', '1529329', '1711005', COUNT(*) AS cnt, COALESCE(LOWER(CONV(BIT_XOR(CAST(CRC32(CONCAT_WS('#', `id`, `user_id`, convert(`game_id` using utf8mb4), convert(`package_name` using utf8mb4), `create_time`, CONCAT(ISNULL(`user_id`), ISNULL(`game_id`), ISNULL(`package_name`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `statisticdb`.`game_daily_life_20220528` FORCE INDEX(`PRIMARY`) WHERE ((`id` >= '1529329')) AND ((`id` <= '1711005')) /*checksum chunk*/'
game_daily_life_20220528该表crash
2.解决方法
对于主从状态修复
切换域名后 kill所有来自线上用户的连接
select concat('KILL ',id,';') from information_schema.processlist where user='';
跳过错误gtid事务号
查看损坏表情况
root@statisticdb 09:30:49>check table game_daily_life_20220528;
+--------------------------------------+-------+----------+-------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+--------------------------------------+-------+----------+-------------------------------------------------------+
| statisticdb.game_daily_life_20220528 | check | warning | 1 client is using or hasn't closed the table properly |
| statisticdb.game_daily_life_20220528 | check | error | Found 3737984 keys of 3737981 |
| statisticdb.game_daily_life_20220528 | check | error | Corrupt |
+--------------------------------------+-------+----------+-------------------------------------------------------+
3.后期改进
db发生异常重启后 对myisam表进行check操作,查看是否有表损坏