生产环境MySQL主主同步主键冲突处理(二)

2014-11-24 17:54:22 · 作者: · 浏览: 4
*****************
id: 1329545
aa: 20130702213504529562
bizOfferId: DK201307021139565210
number: 13991056094
cc: 30.00
fac: 30.22
buyNum: 1
state: 2
type: SJ
create_time: 1372772104
update_time: 1372772474
flag: 100
*************************** 3662. row ***************************
id: 1329546
aa: 20130702213506629648
bizOfferId: DK201307021139588209
number: 15511391791
cc: 30.00
fac: 30.17
buyNum: 1
state: 0
type: SJ
create_time: 1372772106
update_time: 0
flag: 100
*************************** 3663. row ***************************
id: 1329547
aa: 20130702213516595293
bizOfferId: DK201307021139758209
number: 13615611693
cc: 100.00
fac: 99.85
buyNum: 1
state: 2
type: SJ
create_time: 1372772116
update_time: 1372772315
flag: 101



3、在主2上delete from kn_chongzhi where id>=1329544; 并设置自曾ID从1329545开始
mysql> delete from kn_chongzhi where id>=1329544;
Query OK, 0 rows affected (0.00 sec)
mysql> alter table kn_chongzhi auto_increment=1329545;
Query OK, 0 rows affected (0.15 sec)
Records: 0 Duplicates: 0 Warnings: 0


4、主2上slave start,show slave status \G,发现主2同步主1已经ok了;
5、在主2上show master status \G,获取binlog文件名和Position点,在主1上重新change master
6、把上面三条数据保存好,发给程序猿手到录入主1,
PS:当然,如果我按一下设置,肯定不会出现这个问题,如果业务有要求,ID必须连续,那就不能设置这两个参数了:
主1:
auto-increment-increment=2
auto-increment-offset=1
主2:
auto-increment-increment=2
auto-increment-offset=2