使用mk-table-sync总结

mk-table-sync是maatkit里的一个同步主从数据库的利器,执行同步过程中,会同步DELETE,REPLACE,INSERT,UPDATE语句,mk-table-sync把包含前面几个的语句都执行一遍,举个例子来说,主从库上都有:a表,主库上的数据如下:

id      name

1       aa

2       bb

3       cc

4       dd

5       ee

6       ff

从库上的数据如下:

id      name

1       aa

2       bb

3       hh

4       gg

5       ee

那么mk-table-sync会执行3条语句,同步"6 ff"添加到从库,更新"3 cc","4 gg"到从库,一共3条语句,而不是我们看到的从库只比主库少1条数据,其实同步过程中,执行了3条;

执行同步操作一般:

 
  
mk - table - sync -- charset=utf8 --execute --print --no-check-slave -d test -t a \
h=localhost,u='root',p='123456' \
h=192.168.0.24,u='root',p='123456'

注意事项:

1.记得加上--charset选项,否则会造成从库乱码;

2.我们如果想要看下到底哪些数据不同步,可以这样做:

 
  
mk - table - sync -- charset=utf8 --print --no-check-slave -d test -t a \
h = ' 127.0.0.1 ' ,u = ' root ' ,p = ' 123456 ' \
h
= ' 192.168.0.24 ' ,u = ' root ' ,p = ' 123456 ' > result

3.如果有好几个从库的话,建议分开同步,除非几个从库的checksum一样;因为每个从库同步的步调不一定都一致,如果几个从库一块同步的话,很容易造成主键冲突,导致主从同步中断,举个例子来说,建议:

 
  
mk - table - sync -- charset=utf8 --execute --print --no-check-slave -d test -t a \
h = ' 127.0.0.1 ' ,u = ' root ' ,p = ' 123456 ' \
h
= ' 192.168.0.24 ' ,u = ' root ' ,p = ' 123456 ' > result

不建议:

 
  
mk - table - sync -- charset=utf8 --execute --print --no-check-slave -d test -t a \
h = ' 127.0.0.1 ' ,u = ' root ' ,p = ' 123456 ' \
h
= ' 192.168.0.24 ' ,u = ' root ' ,p = ' 123456 ' \
h
= ' 192.168.0.25 ' ,u = ' root ' ,p = ' 123456 ' \
h
= ' 192.168.0.26 ' ,u = ' root ' ,p = ' 123456 ' > result

4.为了减少重复操作,我们也可以一次同步好几个表,比如:

 
  
mk - table - sync --charset=utf8 --execute --print --no-check-slave -d test -t= a,b,c....

转载于:https://www.cnblogs.com/sunss/archive/2011/03/23/1992546.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值