{"id":1681,"date":"2023-03-25T22:35:01","date_gmt":"2023-03-25T14:35:01","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1681"},"modified":"2023-04-23T21:47:54","modified_gmt":"2023-04-23T13:47:54","slug":"alibaba-canal-client-synchronize-rdb","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/alibaba-canal-client-synchronize-rdb\/","title":{"rendered":"\u963f\u91cc\u5df4\u5df4Canal Client\u540c\u6b65RDB"},"content":{"rendered":"<p>\u53c2\u8003\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/alibaba\/canal\/wiki\/Sync-RDB\">https:\/\/github.com\/alibaba\/canal\/wiki\/Sync-RDB<\/a><\/p>\n<h2>\u80cc\u666f<\/h2>\n<p>canal 1.1.1\u7248\u672c\u4e4b\u540e\uff0c\u5185\u7f6e\u589e\u52a0\u5ba2\u6237\u7aef\u6570\u636e\u540c\u6b65\u529f\u80fd\uff0cClient\u9002\u914d\u5668\u6574\u4f53\u4ecb\u7ecd\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/alibaba\/canal\/wiki\/ClientAdapter\" title=\"ClientAdapter\">ClientAdapter<\/a><\/p>\n<p><!-- more --><\/p>\n<h2>RDB\u9002\u914d\u5668<\/h2>\n<p>RDB adapter \u7528\u4e8e\u9002\u914dMySQL\u5230\u4efb\u610f\u5173\u7cfb\u578b\u6570\u636e\u5e93(\u9700\u652f\u6301jdbc)\u7684\u6570\u636e\u540c\u6b65\u53ca\u5bfc\u5165\uff0c\u6d4b\u8bd5\u652f\u6301\u7684\u6570\u636e\u5e93\u5217\u8868:<\/p>\n<ul>\n<li>MySQL<\/li>\n<li>Oracle<\/li>\n<li>Postgress<\/li>\n<li>SQLServer<\/li>\n<\/ul>\n<h3>\u4fee\u6539\u542f\u52a8\u5668\u914d\u7f6e: application.yml<\/h3>\n<p>\u8fd9\u91cc\u4ee5Oracle\u76ee\u6807\u5e93\u4e3a\u4f8b<\/p>\n<pre><code class=\"language-yml\">canal.conf:\n  canalServerHost: 127.0.0.1:11111\n  batchSize: 500\n  syncBatchSize: 1000\n  retries: 0\n  timeout:\n  mode: tcp # kafka rocketMQ\n  srcDataSources:\n    defaultDS:\n      url: jdbc:mysql:\/\/127.0.0.1:3306\/mytest?useUnicode=true\n      username: root\n      password: 121212\n  canalAdapters:\n  - instance: example # canal instance Name or mq topic name\n    groups:\n    - groupId: g1\n      outerAdapters:\n      - name: rdb                                               # \u6307\u5b9a\u4e3ardb\u7c7b\u578b\u540c\u6b65\n        key: oracle1                                            # \u6307\u5b9aadapter\u7684\u552f\u4e00key, \u4e0e\u8868\u6620\u5c04\u914d\u7f6e\u4e2douterAdapterKey\u5bf9\u5e94\n        properties:\n          jdbc.driverClassName: oracle.jdbc.OracleDriver        # jdbc\u9a71\u52a8\u540d, \u90e8\u5206jdbc\u7684jar\u5305\u9700\u8981\u81ea\u884c\u653e\u81f4lib\u76ee\u5f55\u4e0b\n          jdbc.url: jdbc:oracle:thin:@localhost:49161:XE        # jdbc url\n          jdbc.username: mytest                                 # jdbc username\n          jdbc.password: m121212                                # jdbc password\n          threads: 5                                            # \u5e76\u884c\u6267\u884c\u7684\u7ebf\u7a0b\u6570, \u9ed8\u8ba4\u4e3a1<\/code><\/pre>\n<p>\u6ce8\u610f\u70b9:<\/p>\n<ul>\n<li>\u5176\u4e2d<code>outAdapter<\/code>\u7684\u914d\u7f6e\uff1aname\u7edf\u4e00\u4e3a<code>rdb<\/code>\uff0ckey\u4e3a\u5bf9\u5e94\u7684\u6570\u636e\u6e90\u7684\u552f\u4e00\u6807\u8bc6\u9700\u548c\u4e0b\u9762\u7684\u8868\u6620\u5c04\u6587\u4ef6\u4e2d\u7684<code>outerAdapterKey<\/code>\u5bf9\u5e94\uff0c<code>properties<\/code>\u4e3a\u76ee\u6807\u5e93jdb\u7684\u76f8\u5173\u53c2\u6570<\/li>\n<li><code>adapter<\/code>\u5c06\u4f1a\u81ea\u52a8\u52a0\u8f7d<code>conf\/rdb<\/code>\u4e0b\u7684\u6240\u6709<code>.yml<\/code>\u7ed3\u5c3e\u7684\u8868\u6620\u5c04\u914d\u7f6e\u6587\u4ef6<\/li>\n<\/ul>\n<h3>RDB\u8868\u6620\u5c04\u6587\u4ef6<\/h3>\n<p>\u4fee\u6539<code>conf\/rdb\/mytest_user.yml<\/code>\u6587\u4ef6<\/p>\n<pre><code class=\"language-yml\">dataSourceKey: defaultDS        # \u6e90\u6570\u636e\u6e90\u7684key, \u5bf9\u5e94\u4e0a\u9762\u914d\u7f6e\u7684srcDataSources\u4e2d\u7684\u503c\ndestination: example            # cannal\u7684instance\u6216\u8005MQ\u7684topic\ngroupId:                        # \u5bf9\u5e94MQ\u6a21\u5f0f\u4e0b\u7684groupId, \u53ea\u4f1a\u540c\u6b65\u5bf9\u5e94groupId\u7684\u6570\u636e\nouterAdapterKey: oracle1        # adapter key, \u5bf9\u5e94\u4e0a\u9762\u914d\u7f6eoutAdapters\u4e2d\u7684key\nconcurrent: true                # \u662f\u5426\u6309\u4e3b\u952ehash\u5e76\u884c\u540c\u6b65, \u5e76\u884c\u540c\u6b65\u7684\u8868\u5fc5\u987b\u4fdd\u8bc1\u4e3b\u952e\u4e0d\u4f1a\u66f4\u6539\u53ca\u4e3b\u952e\u4e0d\u80fd\u4e3a\u5176\u4ed6\u540c\u6b65\u8868\u7684\u5916\u952e!!\ndbMapping:\n  database: mytest              # \u6e90\u6570\u636e\u6e90\u7684database\/shcema\n  table: user                   # \u6e90\u6570\u636e\u6e90\u8868\u540d\n  targetTable: mytest.tb_user   # \u76ee\u6807\u6570\u636e\u6e90\u7684\u5e93\u540d.\u8868\u540d\n  targetPk:                     # \u4e3b\u952e\u6620\u5c04\n    id: id                      # \u5982\u679c\u662f\u590d\u5408\u4e3b\u952e\u53ef\u4ee5\u6362\u884c\u6620\u5c04\u591a\u4e2a\n#  mapAll: true                 # \u662f\u5426\u6574\u8868\u6620\u5c04, \u8981\u6c42\u6e90\u8868\u548c\u76ee\u6807\u8868\u5b57\u6bb5\u540d\u4e00\u6a21\u4e00\u6837 (\u5982\u679ctargetColumns\u4e5f\u914d\u7f6e\u4e86\u6620\u5c04, \u5219\u4ee5targetColumns\u914d\u7f6e\u4e3a\u51c6)\n  targetColumns:                # \u5b57\u6bb5\u6620\u5c04, \u683c\u5f0f: \u76ee\u6807\u8868\u5b57\u6bb5: \u6e90\u8868\u5b57\u6bb5, \u5982\u679c\u5b57\u6bb5\u540d\u4e00\u6837\u6e90\u8868\u5b57\u6bb5\u540d\u53ef\u4e0d\u586b\n    id:\n    name:\n    role_id:\n    c_time:\n    test1:<\/code><\/pre>\n<p>\u5bfc\u5165\u7684\u7c7b\u578b\u4ee5\u76ee\u6807\u8868\u7684\u5143\u7c7b\u578b\u4e3a\u51c6\uff0c\u5c06\u81ea\u52a8\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362<\/p>\n<h3>Mysql \u5e93\u95f4\u955c\u50cfschema DDL DML\u540c\u6b65<\/h3>\n<p>\u4fee\u6539<code>application.yml<\/code><\/p>\n<pre><code class=\"language-yml\">canalAdapters:\n- instance: example # canal instance Name or mq topic name\ngroups:\n- groupId: g1\n    outerAdapters:\n    - name: rdb\n    key: mysql1\n    properties:\n        jdbc.driverClassName: com.mysql.jdbc.Driver\n        jdbc.url: jdbc:mysql:\/\/192.168.0.36\/mytest?useUnicode=true\n        jdbc.username: root\n        jdbc.password: 121212<\/code><\/pre>\n<p>\u4fee\u6539<code>conf\/rdb\/mytest_user.yml<\/code>\u6587\u4ef6<\/p>\n<pre><code class=\"language-yml\">dataSourceKey: defaultDS\ndestination: example\nouterAdapterKey: mysql1\nconcurrent: true\ndbMapping:\n  mirrorDb: true\n  database: mytest<\/code><\/pre>\n<p>\u5176\u4e2d<code>dbMapping.database<\/code>\u7684\u503c\u4ee3\u8868\u6e90\u5e93\u548c\u76ee\u6807\u5e93\u7684schema\u540d\u79f0\uff0c\u5373\u4e24\u5e93\u7684schema\u8981\u4e00\u6a21\u4e00\u6837<\/p>\n<h3>RDB\u542f\u52a8<\/h3>\n<ul>\n<li>\u5c06\u76ee\u6807\u5e93\u7684jdbc jar\u5305\u653e\u5165lib\u6587\u4ef6\u5939\uff0c\u8fd9\u91cc\u653e\u5165<code>ojdbc6.jar<\/code> (\u5982\u679c\u662f\u5176\u4ed6\u6570\u636e\u5e93\u5219\u653e\u5165\u5bf9\u5e94\u7684\u9a71\u52a8)<\/li>\n<li>\u542f\u52a8<code>canal-adapter<\/code>\u542f\u52a8\u5668<\/li>\n<\/ul>\n<pre><code class=\"language-bash\">bin\/startup.sh<\/code><\/pre>\n<p>\u9a8c\u8bc1 \u4fee\u6539MySQL <code>mytest.user<\/code>\u8868\u7684\u6570\u636e\uff0c\u5c06\u4f1a\u81ea\u52a8\u540c\u6b65\u5230Oracle\u7684<code>MYTEST.TB_USER<\/code>\u8868\u4e0b\u9762\uff0c\u5e76\u4f1a\u6253\u51faDML\u7684log<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u8003\uff1ahttps:\/\/github.com\/alibaba\/canal\/wiki\/Sync-RDB \u80cc\u666f ca [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[417],"tags":[],"class_list":["post-1681","post","type-post","status-publish","format-standard","hentry","category-canal"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1681"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1681\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}