mysql复制使用gtid,用gtid_purged跳过事务

mysql复制使用gtid,用gtid_purged跳过事务

show slave status查看slave状态时,SQL线程停止运行,错误显示Update错误,如果没有使用gtid,可以使用sql_slave_skip_counter跳过,但是开启gtid后,使用该方式是无效的。

    
  1. root@[(none)] 05:36:24> show slave status\G;
  2. *************************** 1. row ***************************
  3.                Slave_IO_State: Waiting for master to send event
  4.                   Master_Host: 10.1.8.24
  5.                   Master_User: repl
  6.                   Master_Port: 3306
  7.                 Connect_Retry: 60
  8.               Master_Log_File: mysql-bin.000009
  9.           Read_Master_Log_Pos: 49413140
  10.                Relay_Log_File: mysqld-relay-bin.000011
  11.                 Relay_Log_Pos: 2043387
  12.         Relay_Master_Log_File: mysql-bin.000002
  13.              Slave_IO_Running: Yes
  14.             Slave_SQL_Running: No
  15.               Replicate_Do_DB: 
  16.           Replicate_Ignore_DB: 
  17.            Replicate_Do_Table: 
  18.        Replicate_Ignore_Table: 
  19.       Replicate_Wild_Do_Table: zabbix.%
  20.   Replicate_Wild_Ignore_Table: 
  21.                    Last_Errno: 1032
  22.                    Last_Error: Could not execute Update_rows event on table zabbix.user_history; Can't find record in 'user_history', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000002, end_log_pos 28739818
  23.                  Skip_Counter: 0
  24.           Exec_Master_Log_Pos: 28739081
  25.               Relay_Log_Space: 783475657
  26.               Until_Condition: None
  27.                Until_Log_File: 
  28.                 Until_Log_Pos: 0
  29.            Master_SSL_Allowed: No
  30.            Master_SSL_CA_File: 
  31.            Master_SSL_CA_Path: 
  32.               Master_SSL_Cert: 
  33.             Master_SSL_Cipher: 
  34.                Master_SSL_Key: 
  35.         Seconds_Behind_Master: NULL
  36. Master_SSL_Verify_Server_Cert: No
  37.                 Last_IO_Errno: 0
  38.                 Last_IO_Error: 
  39.                Last_SQL_Errno: 1032
  40.                Last_SQL_Error: Could not execute Update_rows event on table zabbix.user_history; Can't find record in 'user_history', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000002, end_log_pos 28739818
  41.   Replicate_Ignore_Server_Ids: 
  42.              Master_Server_Id: 1
  43.                   Master_UUID: 7bdd3156-ff10-11e3-91dc-001018a0b030
  44.              Master_Info_File: /var/lib/mysql/master.info
  45.                     SQL_Delay: 0
  46.           SQL_Remaining_Delay: NULL
  47.       Slave_SQL_Running_State: 
  48.            Master_Retry_Count: 86400
  49.                   Master_Bind: 
  50.       Last_IO_Error_Timestamp: 
  51.      Last_SQL_Error_Timestamp: 140928 05:33:17
  52.                Master_SSL_Crl: 
  53.            Master_SSL_Crlpath: 
  54.            Retrieved_Gtid_Set: 7bdd3156-ff10-11e3-91dc-001018a0b030:1-732546
  55.             Executed_Gtid_Set: 7bdd3156-ff10-11e3-91dc-001018a0b030:1-107805 #当前slave执行到的位置
  56.                 Auto_Position: 1
  57. 1 row in set (0.00 sec)
  58. ERROR: 
  59. No query specified


解决办法:

使用
gtid_purged跳过事务,从上面slave状态信息可知,slave当前执行到了
7bdd3156-ff10-11e3-91dc-001018a0b030:1-107805,使用gtid_purged跳过下一个事务
7bdd3156-ff10-11e3-91dc-001018a0b030:1-107806

    
  1. root@[(none)] 05:36:29> stop slave;
  2. Query OK, 0 rows affected (0.05 sec)
  3. root@[(none)] 05:36:35> reset master;
  4. Query OK, 0 rows affected (0.14 sec)
  5. root@[(none)] 05:36:38> set global gtid_purged='7bdd3156-ff10-11e3-91dc-001018a0b030:1-107806'; #跳过事务
  6. Query OK, 0 rows affected (0.13 sec)


查看状态已经恢复正常:
    
  1. root@[(none)] 05:36:57> start slave;show slave status\G;
  2. Query OK, 0 rows affected (0.04 sec)
  3. *************************** 1. row ***************************
  4.                Slave_IO_State: Checking master version
  5.                   Master_Host: 10.1.8.24
  6.                   Master_User: repl
  7.                   Master_Port: 3306
  8.                 Connect_Retry: 60
  9.               Master_Log_File: mysql-bin.000009
  10.           Read_Master_Log_Pos: 49436416
  11.                Relay_Log_File: mysqld-relay-bin.000011
  12.                 Relay_Log_Pos: 2043387
  13.         Relay_Master_Log_File: mysql-bin.000002
  14.              Slave_IO_Running: Yes
  15.             Slave_SQL_Running: Yes
  16.               Replicate_Do_DB: 
  17.           Replicate_Ignore_DB: 
  18.            Replicate_Do_Table: 
  19.        Replicate_Ignore_Table: 
  20.       Replicate_Wild_Do_Table: zabbix.%
  21.   Replicate_Wild_Ignore_Table: 
  22.                    Last_Errno: 0
  23.                    Last_Error: 
  24.                  Skip_Counter: 0
  25.           Exec_Master_Log_Pos: 28739081
  26.               Relay_Log_Space: 783498933
  27.               Until_Condition: None
  28.                Until_Log_File: 
  29.                 Until_Log_Pos: 0
  30.            Master_SSL_Allowed: No
  31.            Master_SSL_CA_File: 
  32.            Master_SSL_CA_Path: 
  33.               Master_SSL_Cert: 
  34.             Master_SSL_Cipher: 
  35.                Master_SSL_Key: 
  36.         Seconds_Behind_Master: 256354
  37. Master_SSL_Verify_Server_Cert: No
  38.                 Last_IO_Errno: 0
  39.                 Last_IO_Error: 
  40.                Last_SQL_Errno: 0
  41.                Last_SQL_Error: 
  42.   Replicate_Ignore_Server_Ids: 
  43.              Master_Server_Id: 1
  44.                   Master_UUID: 7bdd3156-ff10-11e3-91dc-001018a0b030
  45.              Master_Info_File: /var/lib/mysql/master.info
  46.                     SQL_Delay: 0
  47.           SQL_Remaining_Delay: NULL
  48.       Slave_SQL_Running_State: Waiting for the next event in relay log
  49.            Master_Retry_Count: 86400
  50.                   Master_Bind: 
  51.       Last_IO_Error_Timestamp: 
  52.      Last_SQL_Error_Timestamp: 
  53.                Master_SSL_Crl: 
  54.            Master_SSL_Crlpath: 
  55.            Retrieved_Gtid_Set: 7bdd3156-ff10-11e3-91dc-001018a0b030:1-732563
  56.             Executed_Gtid_Set: 7bdd3156-ff10-11e3-91dc-001018a0b030:1-107806
  57.                 Auto_Position: 1
  58. 1 row in set (0.00 sec)
  59. ERROR: 
  60. No query specified


转载于:https://my.oschina.net/anthonyyau/blog/322760

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/109717.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号