跳过事务,新葡京32450网址1.跳过指定数量的事务

发布时间:2019-09-23  栏目:数据  评论:0 Comments

mysql 的骨干错误跳过和mariadb的多源主从复制错误跳过操作不相同,请留意:
变动会话的default_master_connection变量

跳过错误有三种格局:
1.跳过钦定数量的作业:
mysql>slave stop;
mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1       
#跳过三个事情
mysql>slave start

MySQL GTID复制错误管理之跳过荒唐,mysqlgtid

某Slave报错新闻:

mysql> show slave status\G;

新葡京32450网址 1

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.206.140
                  Master_User: u_repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 499
               Relay_Log_File: localhost-relay-bin.000002
                Relay_Log_Pos: 367
        Relay_Master_Log_File: mysql-bin.000001
             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: 1007
                   Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction '9e2c7c0f-0908-11e7-8230-000c29ab7544:1' at master log mysql-bin.000001, end_log_pos 313. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 154
              Relay_Log_Space: 1513
              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: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 1007
               Last_SQL_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction '9e2c7c0f-0908-11e7-8230-000c29ab7544:1' at master log mysql-bin.000001, end_log_pos 313. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any.
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 140
                  Master_UUID: 9e2c7c0f-0908-11e7-8230-000c29ab7544
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: 
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 170316 04:25:29
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 9e2c7c0f-0908-11e7-8230-000c29ab7544:1-2
            Executed_Gtid_Set: 347cbac6-0906-11e7-b957-000c2981a46e:1,
c59a2526-08fd-11e7-a5c7-000c296f2953:1-2
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

ERROR: 
No query specified

View Code

GTID的复制对于错误音信的可读性不是很好,但可以透过错误代码(1007)从监控表replication_applier_status_by_worker查看:

mysql> select * from performance_schema.replication_applier_status_by_worker where LAST_ERROR_NUMBER=1007\G

新葡京32450网址 2

mysql> select * from performance_schema.replication_applier_status_by_worker where LAST_ERROR_NUMBER=1007\G
*************************** 1. row ***************************
         CHANNEL_NAME: 
            WORKER_ID: 2
            THREAD_ID: NULL
        SERVICE_STATE: OFF
LAST_SEEN_TRANSACTION: 9e2c7c0f-0908-11e7-8230-000c29ab7544:1
    LAST_ERROR_NUMBER: 1007
   LAST_ERROR_MESSAGE: Worker 1 failed executing transaction '9e2c7c0f-0908-11e7-8230-000c29ab7544:1' at master log mysql-bin.000001, end_log_pos 313; Error 'Can't create database 'mydb'; database exists' on query. Default database: 'mydb'. Query: 'create database mydb'
 LAST_ERROR_TIMESTAMP: 2017-03-16 04:25:29
1 row in set (0.00 sec)

View Code

利用GTID跳过错误的章程:找到错误的GTID跳过(通过Exec_Master_Log_Pos去binlog里找GTID,或则通过上边监察和控制表replication_applier_status_by_worker找到GTID,也足以通过Executed_Gtid_Set算出GTID),这里运用监督表来找到错误的GTID。找到GTID之后,跳过不当的手续

mysql> stop slave; #停止同步
Query OK, 0 rows affected (0.02 sec)

mysql> set @@session.gtid_next='9e2c7c0f-0908-11e7-8230-000c29ab7544:1';  #跳过错误的GTID
Query OK, 0 rows affected (0.00 sec)

mysql> begin; #提交一个空事务,因为设置gtid_next后,gtid的生命周期就开始了,必须通过显性的提交一个事务来结束,否则报错:ERROR 1790 (HY000): @@SESSION.GTID_NEXT cannot be changed by a client that owns a
Query OK, 0 rows affected (0.00 sec)

mysql> commit;
Query OK, 0 rows affected (0.01 sec)

mysql> set @@session.gtid_next=automatic; #设置回自动模式  
Query OK, 0 rows affected (0.00 sec)

mysql> start slave;
Query OK, 0 rows affected (0.02 sec)

重新确认slave同步情状

mysql> show slave status\G;

新葡京32450网址 3

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.206.140
                  Master_User: u_repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 499
               Relay_Log_File: localhost-relay-bin.000004
                Relay_Log_Pos: 454
        Relay_Master_Log_File: mysql-bin.000002
             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: 499
              Relay_Log_Space: 2024
              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: 140
                  Master_UUID: 9e2c7c0f-0908-11e7-8230-000c29ab7544
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 9e2c7c0f-0908-11e7-8230-000c29ab7544:1-2
            Executed_Gtid_Set: 347cbac6-0906-11e7-b957-000c2981a46e:1,
9e2c7c0f-0908-11e7-8230-000c29ab7544:1-2,
c59a2526-08fd-11e7-a5c7-000c296f2953:1-2
                Auto_Position: 1
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

ERROR: 
No query specified

View Code

打完收工

正文地址:

GTID复制错误处理之跳过荒唐,mysqlgtid
某Slave报错音讯: mysql show slave status\G; mysql show slave
status\G; *************************** 1 .
row **********…

后天我们任重先生而道远看主从情势下,三种跳过荒唐的主意,跳过职业,照旧跳过event?这么些在前头其实大家一贯都以忽视的,那在大家怜惜宗旨进度中,很轻易就变成基本数据更大的分裂。
测验机器5.7.18 主从 gtid 开启
主库数据
新葡京32450网址 4
从库数据
新葡京32450网址 5
很扎眼主从数据有三个不直接的地方,从库少了一条(28,2)
的多少。那年主库开启以下专业:
新葡京32450网址 6
那势必导致从库出现谬误,报1032谬误,如下所示:
mysql> show slave status\G;
***1. row***
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.56
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000023
Read_Master_Log_Pos: 1928
Relay_Log_File: hadoop2-relay-bin.000012
Relay_Log_Pos: 1595
Relay_Master_Log_File: mysql-bin.000023
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: 1032
Last_Error: Could not execute Delete_rows event on table
yhtest1.yhtest; Can’t find record in ‘yhtest’, Error_code: 1032;
handler error HA_ERR_KEY_NOT_FOUND; the event’s master log
mysql-bin.000023, end_log_pos 1812
Skip_Counter: 0
Exec_Master_Log_Pos: 1502
Relay_Log_Space: 2384
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: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1032
Last_SQL_Error: Could not execute Delete_rows event on table
yhtest1.yhtest; Can’t find record in ‘yhtest’, Error_code: 1032;
handler error HA_ERR_KEY_NOT_FOUND; the event’s master log
mysql-bin.000023, end_log_pos 1812
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: ab8c3ec3-b588-11e7-a769-000c29c57be6
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: 171130 23:55:18
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: ab8c3ec3-b588-11e7-a769-000c29c57be6:96-101
Executed_Gtid_Set: ab8c3ec3-b588-11e7-a769-000c29c57be6:1:77-100,
b6ddfda0-d8bc-4272-a58f-4ea75acbbc79:1-22:1000012-1000013:2000012-2000013,
d24c1c76-b4ef-11e7-969a-000c29a75f68:1-17
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.01 sec)

 

STOP SLAVE 'slave_account';
SET @@default_master_connection = 'slave_account';
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
START SLAVE 'slave_account';
SET @@default_master_connection = '';

2.修改mysql的布置文件,通过slave_skip_errors参数来跳全部不当或钦定项指标一无是处
vi /etc/my.cnf
[mysqld]
#slave-skip-errors=1062,1053,1146 #跳过钦定error no类型的荒唐
#slave-skip-errors=all #跳过全体错误

解决措施:
方法1
5.7下,由于开启了GTID ,不可能因而参数sql_slave_skip_counter=N
跳过错误,可是大家可以透过在从库实行空事物的方法,跳过该错误,但要注意,这样跳过的是贰个东西。
从上述报错消息中,大家很轻易看到如今实施职分在:
ab8c3ec3-b588-11e7-a769-000c29c57be6:1:77-100 也正是报错地方在:
ab8c3ec3-b588-11e7-a769-000c29c57be6:1:77-101
操作如下:
新葡京32450网址 7
其不常候,大家再一次show slave status\G
看到主旨已经复苏平常,不过我们再对照数据,发掘我们刚刚主库的四个event
在同四个平地风波中,被大家整整跳过了,也正是四个插入数据也从未在从库实践!
主库数据:
新葡京32450网址 8
从库数据:
新葡京32450网址 9

GTID复制规范的复制错误有二种:
1,数据对象等级的不当,满含主库上update的数额在从库上不设有,主从逐步争辩,库表索引等指标的抵触等等,
  
借使是纯粹的跳过错误的话,这一类的一无所能须要跳过思路是找到主库binlog中对应的事务Id然后在从库上跳过就可以。
2,日志找不到的失实,也即从库在实行利用主库上的binlog推行相应的事务的时候,因为主库上日志被剔除,找不到相应的日志的荒谬
  
这一类的荒唐,根据主库的gtid_purged,更新从库的gtid_purged,也正是报告从库,直接跳过主库中被删除的日记。

方法2
假定大家认为以上办法步骤相当多,还足以借住与pt-slave-restart
来举行主从错误跳过,跳过方法如下:
新葡京32450网址 10
本条同样能够高达跳过主从错误的指标!可是其跳过的单位也是业务,同样也会变成主库所做的多少个插入未有在从库进行!
方法3
利用slave_exec_mode参数来管理主从中遇到的荒唐,操作步骤如下:

正文说的是率先种错误。

stop slave;
set global slave_exec_mode=’IDEMPOTENT’; 幂等形式(暗中认可是STCRUISERICT严谨格局)
start slave;
翻开主从数据
新葡京32450网址 11
发觉一样了,约等于说在调动参数slave_exec_mode后,我们跳过的delete
错误,不过几个插入操作任然是施行的,同临时间,查看错误日志,大家开采记录如下:
新葡京32450网址 12
方法4
利用参数slave_skip_errors跳过荒唐,操作方法如下,在布署文件中增多slave_skip_errors=1062,1032
等,重启数据库,运转slave ,也会发觉测量试验结果和艺术3毫无二致。但是slave_skip_errors 不扶助动态修改!
方法5
从库1032时,大家直接去主库找到相应的笔录,插入到从库个中,restart
salve, 1062 时 大家平素在从库中备份删除掉争论记录就可以。

背景:安装完master之后,修改root密码的时候忘了关闭binlog,导致update
mysql.user表的时候记录了binlog 

此间稍微提一下:mariadb 的Gtid
错误,我们得以应用参数sql_slave_skip_counter=N直接跳过,但是,却不扶助选择pt-slave-restart
跳过错误,何况mariadb 的Gtid
和法定不通用,达成原理同样,达成方式缺差异,所以大家也不能够用这三个本子之间搭建gtid主从。

拉开GTID的复制后,直接报错:
Could not execute Update_rows event on table mysql.user; Can’t find
record in ‘user’, Error_code: 1032; handler error
HA_ERR_KEY_NOT_FOUND; the event’s master log binlog.000002,
end_log_pos 744

新葡京32450网址 13

英特网有不行多的跳过GTID复制报错的作品,
当然GTID复制报错的原因有二种:
一种是多少分歧样引起的(主库事物在从库上找不到相应数据,也许是数量主键争辨,索引争辩之类的)
另一种是主库上东西日志被清理,从库找不到主库的要重放的事物日志引起的(Got
fatal error 1236 from master when reading data from binary log:)
可想而知这里是因为数量不平等引起的谬误,最重视的是哪些找到引起复制错误的事物号,然后跳过那一个东西?
在此以前注意过那个细节难点,此番果然又遇见了。

 

留下评论

网站地图xml地图