Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2111927
  • 博文数量: 317
  • 博客积分: 5670
  • 博客等级: 大校
  • 技术积分: 3677
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-10 17:51
文章分类

全部博文(317)

文章存档

2016年(2)

2015年(44)

2014年(68)

2013年(42)

2012年(23)

2011年(51)

2010年(67)

2009年(17)

2008年(3)

分类: Mysql/postgreSQL

2012-09-28 00:34:04

是里的一个同步主从数据库的利器,执行同步过程中,会同步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....
阅读(1354) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~