免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1958 | 回复: 1
打印 上一主题 下一主题

MySQL工具包Maaikit之mk-table-sync解析 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-10 23:36 |只看该作者 |倒序浏览
MySQL工具包Maaikit之mk-table-sync解析


















mk-table-sync解析
  1. 01.Usage: /home/falcon/perl5/bin/mk-table-sync [OPTION]... DSN [DSN]...

  2. 02.

  3. 03.Options:

  4. 04.

  5. 05.  --algorithms              Algorithm to use when comparing the tables, in order

  6. 06.                            of preference (default Chunk,Nibble,GroupBy,Stream)

  7. 07.  --ask-pass                Prompt for a password when connecting to MySQL

  8. 08.  --[no]bin-log             Log to the binary log (SET SQL_LOG_BIN=1) (default

  9. 09.                            yes)

  10. 10.  --buffer-in-mysql         Instruct MySQL to buffer queries in its memory

  11. 11.  --[no]buffer-to-client    Fetch rows one-by-one from MySQL while comparing

  12. 12.                            (default yes)

  13. 13.  --charset             -A  Default character set

  14. 14.  --[no]check-master        With --sync-to-master, try to verify that the

  15. 15.                            detected master is the real master (default yes)

  16. 16.  --[no]check-privileges    Check that user has all necessary privileges on

  17. 17.                            source and destination table (default yes)

  18. 18.  --[no]check-slave         Check whether the destination server is a slave

  19. 19.                            (default yes)检测目标服务器是否为从

  20. 20.  --[no]check-triggers      Check that no triggers are defined on the

  21. 21.                         destination table (default yes)检测是否在目标服务器上有触发器

  22. 22.  --chunk-column            Chunk the table on this column

  23. 23.  --chunk-index             Chunk the table using this index

  24. 24.  --chunk-size              Number of rows or data size per chunk (default 1000)

  25. 25.  --columns             -c  Compare this comma-separated list of columns

  26. 26.  --config                  Read this comma-separated list of config files; if

  27. 27.                            specified, this must be the first option on the

  28. 28.                            command line

  29. 29.  --databases           -d  Sync only this comma-separated list of databases

  30. 30.  --defaults-file       -F  Only read mysql options from the given file

  31. 31.  --dry-run                 Analyze, decide the sync algorithm to use, print and

  32. 32.                            exit

  33. 33.  --engines             -e  Sync only this comma-separated list of storage

  34. 34.                            engines

  35. 35.  --execute                 Execute queries to make the tables have identical

  36. 36.                            data

  37. 37.  --explain-hosts           Print connection information and exit

  38. 38.  --float-precision         Precision for FLOAT and DOUBLE column comparisons

  39. 39.  --[no]foreign-key-checks  Enable foreign key checks (SET FOREIGN_KEY_CHECKS=1)

  40. 40.                            (default yes)

  41. 41.  --function                Which hash function you'd like to use for checksums

  42. 42.  --help                    Show help and exit

  43. 43.  --host                -h  Connect to host

  44. 44.  --ignore-columns          Ignore this comma-separated list of column names in

  45. 45.                            comparisons

  46. 46.  --ignore-databases        Ignore this comma-separated list of databases

  47. 47.  --ignore-engines          Ignore this comma-separated list of storage engines

  48. 48.                            (default FEDERATED,MRG_MyISAM)

  49. 49.  --ignore-tables           Ignore this comma-separated list of tables

  50. 50.  --[no]index-hint          Add FORCE/USE INDEX hints to the chunk and row

  51. 51.                            queries (default yes)

  52. 52.  --lock                    Lock tables: 0=none, 1=per sync cycle, 2=per table,

  53. 53.                            or 3=globally

  54. 54.  --lock-and-rename         Lock the source and destination table, sync, then

  55. 55.                            swap names

  56. 56.  --password            -p  Password to use when connecting

  57. 57.  --pid                     Create the given PID file

  58. 58.  --port                -P  Port number to use for connection

  59. 59.  --print                   Print queries that will resolve differences

  60. 60.  --recursion-method        Preferred recursion method used to find slaves

  61. 61.  --replace                 Write all INSERT and UPDATE statements as REPLACE

  62. 62.  --replicate               Sync tables listed as different in this table

  63. 63.  --set-vars                Set these MySQL variables (default

  64. 64.                            wait_timeout=10000)

  65. 65.  --socket              -S  Socket file to use for connection

  66. 66.  --sync-to-master          Treat the DSN as a slave and sync it to its master

  67. 67.  --tables              -t  Sync only this comma-separated list of tables

  68. 68.  --timeout-ok              Keep going if --wait fails

  69. 69.  --[no]transaction         Use transactions instead of LOCK TABLES

  70. 70.  --trim                    TRIM() VARCHAR columns in BIT_XOR and ACCUM modes

  71. 71.  --[no]unique-checks       Enable unique key checks (SET UNIQUE_CHECKS=1)

  72. 72.                            (default yes)是否进行唯一性检测

  73. 73.  --user                -u  User for login if not current user

  74. 74.  --verbose             -v  Print results of sync operations

  75. 75.  --version                 Show version and exit

  76. 76.  --wait                -w  How long to wait for slaves to catch up to their

  77. 77.                            master.  Optional suffix s=seconds, m=minutes,

  78. 78.                            h=hours, d=days; if no suffix, s is used.

  79. 79.  --where                   WHERE clause to restrict syncing to part of the

  80. 80.                            table

  81. 81.

  82. 82.Rules:

  83. 83.

  84. 84.  Specify at least one of --print, --execute, or --dry-run.

  85. 85.  --where and --replicate are mutually exclusive.

  86. 86.

  87. 87.DSN syntax is key=value[,key=value...]  Allowable DSN keys:

  88. 88.

  89. 89.  KEY  COPY  MEANING

  90. 90.  ===  ====  =============================================

  91. 91.  A    yes   Default character set

  92. 92.  D    yes   Database containing the table to be synced

  93. 93.  F    yes   Only read default options from the given file

  94. 94.  P    yes   Port number to use for connection

  95. 95.  S    yes   Socket file to use for connection

  96. 96.  h    yes   Connect to host

  97. 97.  p    yes   Password to use when connecting

  98. 98.  t    yes   Table to be synced

  99. 99.  u    yes   User for login if not current user

  100. 100.

  101. 101.  If the DSN is a bareword, the word is treated as the 'h' key.

  102. 102.

  103. 103.Options and values after processing arguments:

  104. 104.

  105. 105.  --algorithms              Chunk,Nibble,GroupBy,Stream

  106. 106.  --ask-pass                FALSE

  107. 107.  --bin-log                 TRUE

  108. 108.  --buffer-in-mysql         FALSE

  109. 109.  --buffer-to-client        TRUE

  110. 110.  --charset                 (No value)

  111. 111.  --check-master            TRUE

  112. 112.  --check-privileges        TRUE

  113. 113.  --check-slave             TRUE

  114. 114.  --check-triggers          TRUE

  115. 115.  --chunk-column            (No value)

  116. 116.  --chunk-index             (No value)

  117. 117.  --chunk-size              1000

  118. 118.  --columns                 (No value)

  119. 119.  --config                  /etc/maatkit/maatkit.conf,/etc/maatkit/mk-table-sync.conf,/home/falcon/.maatkit.conf,/home/falcon/.mk-table-sync.conf

  120. 120.  --databases               (No value)

  121. 121.  --defaults-file           (No value)

  122. 122.  --dry-run                 FALSE

  123. 123.  --engines                 (No value)

  124. 124.  --execute                 FALSE

  125. 125.  --explain-hosts           FALSE

  126. 126.  --float-precision         (No value)

  127. 127.  --foreign-key-checks      TRUE

  128. 128.  --function                (No value)

  129. 129.  --help                    TRUE

  130. 130.  --host                    (No value)

  131. 131.  --ignore-columns         

  132. 132.  --ignore-databases        

  133. 133.  --ignore-engines          FEDERATED,MRG_MyISAM

  134. 134.  --ignore-tables           

  135. 135.  --index-hint              TRUE

  136. 136.  --lock                    (No value)

  137. 137.  --lock-and-rename         FALSE

  138. 138.  --password                (No value)

  139. 139.  --pid                     (No value)

  140. 140.  --port                    (No value)

  141. 141.  --print                   FALSE

  142. 142.  --recursion-method        (No value)

  143. 143.  --replace                 FALSE

  144. 144.  --replicate               (No value)

  145. 145.  --set-vars                wait_timeout=10000

  146. 146.  --socket                  (No value)

  147. 147.  --sync-to-master          FALSE

  148. 148.  --tables                  (No value)

  149. 149.  --timeout-ok              FALSE

  150. 150.  --transaction             FALSE

  151. 151.  --trim                    FALSE

  152. 152.  --unique-checks           TRUE

  153. 153.  --user                    (No value)

  154. 154.  --verbose                 0

  155. 155.  --version                 FALSE

  156. 156.  --wait                    (No value)

  157. 157.  --where                   (No value)
  158. 复制代码
复制代码
同步2个mysql库的相同表,只需要指定--databases参数即可,如:
  1. 01.$mk-table-sync --execute --print --databases mooo\h=192.168.2.5:3306,u=falcon,p=falcon,P=3306  \h=192.168.2.5:3310,u=falcon,p=falcon,P=3310
  2. 复制代码
复制代码
同步主从服务器上非主从同步范围的库,用上面方法就会报REPLICATION SAFETY复制安全性的错误提示,解决办法是添加 --no-check-slave 参数
  1. 01.$mk-table-sync --execute --print --no-check-slave --databases mooo \h=192.168.2.5:3306,u=falcon,p=falcon,P=3306 \ (主)h=192.168.2.5:3307,u=falcon,p=falcon,P=3307   (从)   
  2. 复制代码
复制代码
当主从数据不同步时,这里有一个技巧可以让主同步从的数据即调换主从同步的DSN参数顺序,注意:这时需要关闭主的binlog日志,否则当从的数据同步到主后,同步的数据写入主的binlog会反过来同步到从服务器导致从的数据重复,如:
  1. 01.$mk-table-sync [OPTION] slave-DSN  master-DSN$mk-table-sync --execute --print --no-bin-log --databases test --tables tb01 \h=192.168.2.5:3307,u=falcon,p=falcon,P=3307 (从)h=192.168.2.5:3306,u=falcon,p=falcon,P=3306(主)
  2. 复制代码
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-12-21 22:58 |只看该作者
谢谢分享  希望于楼主多多交流
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP