Mysql学习MySQL中主从复制重复键问题修复方法

Mysql学习MySQL中主从复制重复键问题修复方法,第1张

概述介绍《Mysql学习MySQL中主从复制重复键问题修复方法》开发教程,希望对您有用。

《MysqL学习MysqL中主从复制重复键问题修复方法》要点:
本文介绍了MysqL学习MysqL中主从复制重复键问题修复方法,希望对您有用。如果有疑问,可以联系我们。

-------------------quote begin------------------------ 3. If you decIDe that you can skip the next statement from the master,issue the following statements: MysqL> SET GLOBAL sql_SLAVE_SKIP_COUNTER = n; MysqL> START SLAVE; The value of n should be 1 if the next statement from the master does not use auto_INCREMENT or LAST_INSERT_ID(). Otherwise,the value should be 2. The reason for using a value of 2 for statements that use auto_INCREMENT or LAST_INSERT_ID() is that they take two events in the binary log of the master.MysqL入门

-------------------quote end------------------------MysqL入门

MysqL文档中的意思是当master传到slave的语句中要用到auto_increment,或者last_insert_ID()时,需要skip两个event. 但实际情况并非如此MysqL入门

测试过程如下: 172.16.161.26 为master 172.16.161.15 为slave 同步c2cdb,初始状态okMysqL入门

1. 在master上创建测试表MysqL入门

MysqL> create table tmp_test_0208(ID int not null auto_increment,name varchar(30),primary key(ID)) engine=innodb;query OK,0 rows affected (0.20 sec)

2,在salve上insert 3条记录MysqL入门

MysqL> insert into tmp_test_0208 values(1,'a'),(2,'b'),(3,'c');query OK,3 rows affected (0.00 sec)Records: 3 Duplicates: 0 Warnings: 0MysqL> select * from tmp_test_0208;+----+------+| ID | name |+----+------+| 1 | a || 2 | b || 3 | c |+----+------+3 rows in set (0.00 sec)

3,在master上insert 3条记录 MysqL入门

MysqL> insert into tmp_test_0208(name) values('a'),('b'),('c');query OK,3 rows affected (0.02 sec)Records: 3 Duplicates: 0 Warnings: 0MysqL> select * from tmp_test_0208;+----+------+| ID | name |+----+------+| 1 | a || 2 | b || 3 | c |+----+------+3 rows in set (0.00 sec)

4,  slave 的sql thread 中止MysqL入门

/usr/local/MysqL/bin/MysqL -uroot -pxxx c2cdb -s -e "show slave status\G" |egrep "Slave_IO_Running|Slave_sql_Running"Slave_IO_Running: YesSlave_sql_Running: No

5,  skip next statemate后start slave正常 MysqL入门

MysqL> SET GLOBAL sql_SLAVE_SKIP_COUNTER = 1 ;query OK,0 rows affected (0.00 sec)MysqL> slave start;query OK,0 rows affected (0.00 sec)/usr/local/MysqL/bin/MysqL -uroot -pxxx c2cdb -s -e "show slave status\G" |egrep "Slave_IO_Running|Slave_sql_Running"Slave_IO_Running: YesSlave_sql_Running: Yes

slave端errlog如下: 070208 16:07:59[ERROR] Slave: Error 'Duplicate entry '1' for key 1' on query. Default database: 'c2cdb'. query: 'insert into tmp_te st_0208(name) values('a'),('c')',Error_code: 1062MysqL入门

070208 16:07:59 [ERROR] Error running query,slave sql thread aborted. Fix the problem,and restart the slave sql thread with "SLAVE  START". We stopped at log 'db_auction1-bin.000203' position 14215101MysqL入门

070208 16:09:59 [Note] Slave sql thread initialized,starting replication in log 'db_auction1-bin.000203' at position 14215101,rela y log './db_auction1_b-relay-bin.000457' position: 200682931MysqL入门

 MysqL入门

master羰binlog中相应的记录如下:MysqL入门

# at 14215101 #070208 16:08:00 server ID 1  log_pos 14215101  Intvar SET INSERT_ID=1; # at 14215129 #070208 16:08:00 server ID 1  log_pos 14215129  query   thread_ID=2744782       exec_time=0     error_code=0 SET TIMESTAMP=1170922080; insert into tmp_test_0208(name) values('a'),('c');MysqL入门

总结:使用SET GLOBAL sql_SLAVE_SKIP_COUNTER 命令跳过失败的sqlMysqL入门

总结

以上是内存溢出为你收集整理的Mysql学习MySQL中主从复制重复键问题修复方法全部内容,希望文章能够帮你解决Mysql学习MySQL中主从复制重复键问题修复方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/1163257.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-01
下一篇2022-06-01

发表评论

登录后才能评论

评论列表(0条)

    保存