一 从库中断信息
Slave_IO_State: Waiting for master to send event 故障表名已经替换 Master_Host: 10.10.10.3 Master_User: rep Master_Port: 3306 Connect_Retry: 10 Master_Log_File: mysql-bin.017486 Read_Master_Log_Pos: 337817815 Relay_Log_File: relay-bin.020353 Relay_Log_Pos: 63272569 Relay_Master_Log_File: mysql-bin.017486 Slave_IO_Running: Yes Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 1034 Last_Error: Could not execute Write_rows_v1 event on table school.student; Table school/student in tablespace 5065 corrupted., Error_code: 126; Index for table 'student' is corrupt; try to repair it, Error_code: 1034; handler error HA_ERR_CRASHED; the event's master log mysql-bin.017486, end_log_pos 112187504 Skip_Counter: 0 Exec_Master_Log_Pos: 112185362 Relay_Log_Space: 2549518298 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 1034 Last_SQL_Error: Could not execute Write_rows_v1 event on table school.student; Table school/student in tablespace 5065 corrupted., Error_code: 126; Index for table 'student' is corrupt; try to repair it, Error_code: 1034; handler error HA_ERR_CRASHED; the event's master log mysql-bin.017486, end_log_pos 112187504 Replicate_Ignore_Server_Ids: Master_Server_Id: 2541816 Using_Gtid: Slave_Pos Gtid_IO_Pos: 0-2541816-46995033790 Replicate_Do_Domain_Ids: Replicate_Ignore_Domain_Ids: Parallel_Mode: conservative SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State:
二 修复过程
1.非常重要,从库先停止复制(虽然sql进程已停止),设置过滤复制表 student
https://mariadb.com/kb/en/replication-and-binary-log-system-variables/#replicate_ignore_table
stop slave; set global REPLICATE_IGNORE_TABLE='school.student';
动态调整检查
SELECT VARIABLE_NAME, SESSION_VALUE, GLOBAL_VALUE FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE VARIABLE_NAME like '%ignore%'; +-----------------------------+---------------+-----------------+ | VARIABLE_NAME | SESSION_VALUE | GLOBAL_VALUE | +-----------------------------+---------------+-----------------+ | IGNORE_BUILTIN_INNODB | NULL | OFF | | REPLICATE_IGNORE_TABLE | NULL | school.student | | GTID_IGNORE_DUPLICATES | NULL | OFF | | REPLICATE_IGNORE_DB | NULL | | | IGNORE_DB_DIRS | NULL | | | REPLICATE_WILD_IGNORE_TABLE | NULL | | +-----------------------------+---------------+-----------------+ 6 rows in set (0.00 sec)
2.去主库或者从库备份表,得到同步位置,并拷贝到故障从库
--在从库备份表 /apps/svr/mariadb10/bin/mysqldump --opt --single-transaction --dump-slave=2 -S /tmp/mysql3309.sock -udba -p*** school student > /apps/tmp/student.sql 在主库备份表 /apps/svr/mariadb10/bin/mysqldump --opt --single-transaction --master-data=2 -S /tmp/mysql3309.sock -udba -p*** school student > /apps/tmp/student.sql -- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000006', MASTER_LOG_POS=41947;
3.从库执行复制
START SLAVE UNTIL MASTER_LOG_FILE = 'mysql-bin.000006', MASTER_LOG_POS = 41947;
当sql 线程停止时检查停止位置是否正确
Relay_Master_Log_File: mysql-bin.000006 Exec_Master_Log_Pos: 41947 Slave_IO_Running: Yes Slave_SQL_Running: No Replicate_Ignore_Table: school.student Until_Condition: Master Until_Log_File: mysql-bin.000006 Until_Log_Pos: 41947
从库导入备份数据(删除旧表,重建表导入数据)
set session sql_log_bin=0; source /apps/tmp/student.sql;
关闭过滤复制
stop slave;set global REPLICATE_IGNORE_TABLE=''; show slave status \G
4.检查是否正常同步
start slave;
show slave status \G
延伸:
动态设置
-- mysql复制过滤 stop slave sql_thread; CHANGE REPLICATION FILTER REPLICATE_WILD_DO_TABLE = ('school_5.%','school_6.%','school_7.%','school_8.%'); --CHANGE REPLICATION FILTER REPLICATE_WILD_DO_TABLE = (); --CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB = (school); --CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE =(); 过滤复制某个表 --CHANGE REPLICATION FILTER REPLICATE_WILD_IGNORE_TABLE = ('db1.new%', 'db2.new%'); 过滤复制一批表 CHANGE MASTER TO master_host='10.10.10.10',master_port=3309,master_user='repl',master_password='***' , MASTER_AUTO_POSITION=1; start slave; -- mariadb 复制过滤 stop slave; set global REPLICATE_IGNORE_TABLE='school.student'; --具体某个表 -- set global replicate_wild_ignore_table = 'school.student%'; 某个格式的表,以 student 为表头 start slave;
低版本只能配置文件设置,重启生效
#replicate-do-db= #replicate-ignore-db= #replicate-do-table= #replicate-ignore-table= #replicate-wild-do-table= #replicate-wild-ignore-table= #replicate-same-server-id #replicate-rewrite-db= #innodb_replication_delay=0
                    
                
                
            
        
浙公网安备 33010602011771号