昨天和今天都碰到了同样的问题,内网mysql备库上SQL线程一直停留在某个position上
很长一段时间:
mysql> show slave status\G
。。。
Exec_Master_Log_Pos的值一直不变,Seconds_Behind_Master的值在不停的网上升
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.100.65
Master_User: backup
Master_Port: 3301
Connect_Retry: 60
Master_Log_File: mysql-3301-bin.002273
Read_Master_Log_Pos: 661642400
Relay_Log_File: mysql_3302-relay-bin.000015
Relay_Log_Pos: 696155381
Relay_Master_Log_File: mysql-3301-bin.002272
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 696155230
Relay_Log_Space: 1809256918
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 2942
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 100
1 row in set (0.00 sec)
刚开始还以为是sql线程假死了,stop,start slave后问题依旧,也尝试过reset slave,change master等操作,问题也一样,错误日志也没有任何错误信息
后来通过mysqlbinlog分析了相应的binlog日志,发现了大量的delete操作(binlog format 是row格式)
### DELETE FROM
crm.s_orders where XXXX
在主库查询发现这表没有任何的索引,包括主键列也没有
和开发确认后,他们是想delete掉表的大部分的数据,为了尽快解决备库的复制延迟,我打算先停掉备库复制,直接truncate掉这个表
mysql> stop slave;
Query OK, 0 rows affected (1.22 sec)
mysql> truncate table crm.s_orders;
Query OK, 0 rows affected (0.87 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
之后备库很快就恢复的正常的复制
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.100.65
Master_User: backup
Master_Port: 3301
Connect_Retry: 60
Master_Log_File: mysql-3301-bin.002273
Read_Master_Log_Pos: 767677085
Relay_Log_File: mysql_3302-relay-bin.000019
Relay_Log_Pos: 131296556
Relay_Master_Log_File: mysql-3301-bin.002273
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 767677085
Relay_Log_Space: 767677548
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 100
1 row in set (0.00 sec)
主备复制恢复后,创建相应的主键和索引,再把主库上的数据手工同步到备库上。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23249684/viewspace-1356588/
,如需转载,请注明出处,否则将追究法律责任。