使用 TTS 遷移數據時,從庫 SQL 線程報錯:
Last_SQL_Errno: 1146 Last_SQL_Error: Error 'Table 'spider.tb_city_population_rank' doesn't exist' on query. Default database: 'spider'. Query: 'alter table tb_city_population_rank discard tablespace'
或:
Last_SQL_Error: Error 'Table 'spider.tb_city_population_rank' doesn't exist' on query. Default database: 'spider'. Query: 'alter table tb_city_population_rank import tablespace'
SHOW CREATE TABLE xxx1 獲取建表語句CREATE TABLE xxx1 建表,ALTER TABLE xxx1 DISCARD TABLESPACE 刪除 .ibdFLUSH TABLES xxx1,xxx2 FOR EXPORT 刷新內存生成 .cfgscp xxx1.ibd xxx1.cfg B:/data/ 拷貝文件ALTER TABLE xxx1 IMPORT TABLESPACE 導入Last_SQL_Error: ... 'alter table tb_city_population_rank discard tablespace'
原因:從庫磁盤只有 .ibd,缺 .frm(表定義)。SQL 線程重放主庫的 DISCARD 時,表已不存在。
修復步驟:
mv tb_city_population_rank.ibd tb_city_population_rank.ibd.bakCREATE TABLE ... 生成 .frmSTART SLAVE SQL_THREAD,執行 DISCARD,.ibd 再次消失Last_SQL_Error: ... 'alter table tb_city_population_rank import tablespace'
:
mv tb_city_population_rank.ibd.bak tb_city_population_rank.ibdSTART SLAVE SQL_THREAD,IMPORT 成功SELECT * FROM tb_city_population_rank LIMIT 100;「缺什麼補什麼,多什麼減什麼」:按報錯順序逐表修復,核心邏輯是讓從庫文件系統狀態與主庫 binlog 事件預期一致。
SET GLOBAL sql_slave_skip_counter=20; STOP SLAVE; START SLAVE;
跳過錯誤事件(謹慎使用,可能導致數據不一致)。