使用mk-table-sync總結

來源:互聯網
上載者:User

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....

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.