{"id":1502,"date":"2020-06-05T18:45:48","date_gmt":"2020-06-05T10:45:48","guid":{"rendered":"http:\/\/39.97.231.10\/?p=1502"},"modified":"2020-06-05T18:45:48","modified_gmt":"2020-06-05T10:45:48","slug":"mysql%e4%b8%bb%e4%bb%8e%e5%a4%8d%e5%88%b6%e6%9d%a1%e4%bb%b6%e8%bf%87%e6%bb%a4","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=1502","title":{"rendered":"MySQL\u4e3b\u4ece\u590d\u5236\u6761\u4ef6\u8fc7\u6ee4"},"content":{"rendered":"<p>MySQL\u4e3b\u4ece\u590d\u5236\u662f\u903b\u8f91\u590d\u5236\uff0c\u57fa\u4e8eBinlog\u8fdb\u884c\u4e3b\u4ece\u6570\u636e\u4f20\u8f93\uff0cMySQL\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u53c2\u6570\u6765\u914d\u7f6e\u4e3b\u4ece\u590d\u5236\u8fc7\u6ee4\u6761\u4ef6\u3002\u5728\u4e3b\u5e93\u53ef\u4ee5\u8bbe\u7f6e\u5bf9\u4e8e\u5e93\u7684\u6570\u636e\u5199\u5165\u662f\u5426\u5199\u5165binlog\uff0c\u5728\u4ece\u5e93\u53ef\u4ee5\u8bbe\u7f6e\u5bf9\u67d0\u4e9b\u5e93\u6216\u8005\u8868\u7684binlog\u662f\u5426\u5ffd\u7565\u3002\u672c\u6587\u5c06\u7b80\u5355\u63cf\u8ff0MySQL\u4e3b\u4ece\u590d\u5236\u8fc7\u6ee4\u7684\u76f8\u5173\u53c2\u6570\u548c\u5e38\u89c1\u7528\u6cd5\u3002<\/p>\n<ul>\n<li>MySQL\u7248\u672c\uff1a5.7.19<\/li>\n<li>binlog_format\uff1aROW<\/li>\n<\/ul>\n<h4>1. \u662f\u5426\u5199\u5165binlog<\/h4>\n<p>MySQL\u901a\u8fc7\u4ee5\u4e0b\u4e24\u4e2a\u53c2\u6570\u6765\u63a7\u5236\u67d0\u4e9b\u5e93\u662f\u5426\u5199\u5165binlog\u3002<\/p>\n<ul>\n<li>&#8211;binlog-do-db=db_name<\/li>\n<li>&#8211;binlog-ignore-db=db_name<\/li>\n<\/ul>\n<p>&#8211;binlog-do-db \u6307\u5b9a\u7684\u5e93\u540d\uff0c\u5176\u5185\u90e8\u8868\u6570\u636e\u4fee\u6539\u90fd\u4f1a\u5199\u5165binlog\u3002<br \/>\n&#8211;binlog-ignore-db \u6307\u5b9a\u7684\u5e93\u540d\uff0c\u5176\u5185\u90e8\u8868\u6570\u636e\u4fee\u6539\u5c06\u4e0d\u4f1a\u5199\u5165binlog\u3002<br \/>\n\u8fd9\u4e24\u4e2a\u53c2\u6570\u4fee\u6539\u9700\u8981\u91cd\u542fMySQL\uff0c\u65e0\u6cd5\u52a8\u6001\u4fee\u6539\uff0c\u53e6\u5916\u5728show global variables \u7684\u7ed3\u679c\u4e2d\u4e5f\u65e0\u6cd5\u663e\u793a\u8fd9\u4e24\u4e2a\u53c2\u6570\u3002<\/p>\n<h4>2. SQL\u7ebf\u7a0b\u8fc7\u6ee4\u65e5\u5fd7<\/h4>\n<p>\u4ece\u5e93\u590d\u5236\u7684SQL\u7ebf\u7a0b\u4ecerelay log\u91cc\u8bfb\u65e5\u5fd7\uff0c\u5e76\u5e94\u7528\u65e5\u5fd7\uff0c\u901a\u8fc7\u8bbe\u7f6e\u5982\u4e0b\u53c2\u6570\uff0c\u53ef\u4ee5\u63a7\u5236SQL\u7ebf\u7a0b\u6839\u636e\u5e93\u540d\u6216\u8868\u540d\u8fc7\u6ee4\u65e5\u5fd7\u3002<\/p>\n<ul>\n<li>&#8211;replicate-ignore-db=db_name<\/li>\n<li>&#8211;replicate-ignore-table=db_name.tbl_name<\/li>\n<li>&#8211;replicate-do-db=db_name<\/li>\n<li>&#8211;replicate-do-table=db_name.tbl_name<\/li>\n<li>&#8211;replicate-wild-do-table=db_name.tbl_name<\/li>\n<li>&#8211;replicate-wild-ignore-table=db_name.tbl_name<\/li>\n<li>&#8211;replicate-rewrite-db=from_name-&gt;to_name<\/li>\n<\/ul>\n<p>&#8211;replicate-ignore-db \u5ffd\u7565\u67d0\u4e9b\u5e93\u7684binlog \u65e5\u5fd7\u5e94\u7528\u3002<br \/>\n&#8211;replicate-ignore-table \u5ffd\u7565\u67d0\u4e9b\u8868\u7684binlog \u65e5\u5fd7\u5e94\u7528\u3002<br \/>\n&#8211;replicate-do-db \u5e94\u7528\u67d0\u4e9b\u5e93\u7684binlog \u65e5\u5fd7\u3002<br \/>\n&#8211;replicate-do-table \u5e94\u7528\u67d0\u4e9b\u8868\u7684binlog \u65e5\u5fd7\u3002<br \/>\n&#8211;replicate-wild-do-table \u4f7f\u7528\u901a\u914d\u7b26\u6765\u5339\u914d\u90a3\u4e9b\u5e94\u7528binlog\u65e5\u5fd7\u7684\u8868\u3002<br \/>\n&#8211;replicate-wild-ignore-table \u4f7f\u7528\u901a\u914d\u7b26\u6765\u5339\u914d\u90a3\u4e9b\u4e0d\u80fd\u5e94\u7528binlog\u65e5\u5fd7\u7684\u8868\u3002<br \/>\n&#8211;replicate-rewrite-db\uff0c\u80fd\u591f\u5b9e\u73b0\u4e3b\u5e93\u4e0e\u4ece\u5e93\u6570\u636e\u5e93\u540d\u79f0\u4e0d\u540c\u7684\u590d\u5236\uff0c\u6bd4\u5982\u4e3b\u5e93\u6570\u636e\u5e93\u540d\u4e3aA\uff0c\u4ece\u5e93\u6570\u636e\u5e93\u540d\u4e3aB\uff0c\u5b9e\u73b0\u4e3b\u5e93A\u5230\u4ece\u5e93B\u7684\u590d\u5236\u3002<br \/>\n\u4ee5\u4e0a\u8fd9\u4e9b\u53c2\u6570\u540c\u6837\u4e0d\u80fd\u52a8\u6001\u4fee\u6539\uff0c\u9700\u8981\u91cd\u542fMySQL\u751f\u6548\u3002\u5728show global variables \u7684\u7ed3\u679c\u4e2d\u4e5f\u65e0\u6cd5\u663e\u793a\u8fd9\u4e9b\u53c2\u6570\u3002<br \/>\n<strong>\u52a8\u6001\u8bbe\u7f6e\u8fc7\u6ee4\u6761\u4ef6\uff1a<\/strong><br \/>\nMySQL\u63d0\u4f9b\u4e86\u53e6\u5916\u4e00\u79cd\u52a8\u6001\u8bbe\u7f6e\u4ece\u5e93\u7684\u590d\u5236\u8fc7\u6ee4\u6761\u4ef6\u7684\u65b9\u5f0f\uff0cCHANGE REPLICATION FILTER \u8bed\u6cd5\uff0c\u8bbe\u7f6e\u524d\u5148\u505c\u6b62\u590d\u5236\u7684SQL\u7ebf\u7a0b\uff0c\u8bbe\u7f6e\u5b8c\u6210\u540e\uff0c\u518d\u5f00\u542fSQL\u7ebf\u7a0b\u3002\u5177\u4f53\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>CHANGE REPLICATION FILTER filter [, filter][, ...]\nfilter:\n    REPLICATE_DO_DB = (db_list)\n|   REPLICATE_IGNORE_DB = (db_list)\n|   REPLICATE_DO_TABLE = (tbl_list)\n|   REPLICATE_IGNORE_TABLE = (tbl_list)\n|   REPLICATE_WILD_DO_TABLE = (wild_tbl_list)\n|   REPLICATE_WILD_IGNORE_TABLE = (wild_tbl_list)\n|   REPLICATE_REWRITE_DB = (db_pair_list)\ndb_list:\n    db_name[, db_name][, ...]\ntbl_list:\n    db_name.table_name[, db_table_name][, ...]\nwild_tbl_list:\n    \\'db_pattern.table_pattern\\'[, \\'db_pattern.table_pattern\\'][, ...]\ndb_pair_list:\n    (db_pair)[, (db_pair)][, ...]\ndb_pair:\n    from_db, to_db\n<\/pre>\n<p>\u6bd4\u5982\uff0c\u4e0b\u9762\u53ea\u590d\u5236\u5e93\u540d\u4e3adb1\u548cdb2\u4e2d\u7684\u8868\uff1a<br \/>\nCHANGE REPLICATION FILTER REPLICATE_DO_DB = (db1, db2);<br \/>\n\u6bd4\u5982\uff0c\u4e0b\u9762\u540c\u6b65db1.t1\u5f00\u5934\u7684\u8868\uff0c\u8fc7\u6ee4db1.t2\u5f00\u5934\u7684\u8868<br \/>\nCHANGE REPLICATION FILTER<br \/>\nREPLICATE_WILD_DO_TABLE = (\\&#8217;db1.t1%\\&#8217;),<br \/>\nREPLICATE_WILD_IGNORE_TABLE = (\\&#8217;db1.t2%\\&#8217;);<br \/>\n<strong>\u5173\u4e8e\u590d\u5236\u8fc7\u6ee4\uff0c\u6709\u51e0\u70b9\u9700\u8981\u989d\u5916\u6ce8\u610f\uff1a<\/strong><br \/>\n\uff081\uff09\u5982\u679c\u4e00\u4e2abinlog\u4e8b\u52a1\u91cc\u6709\u591a\u4e2aSQL\uff0c\u5176\u4e2d\u6d89\u53ca\u5230\u8fc7\u6ee4\u5e93\u540d\u6216\u8005\u8868\u540d\u7684SQL\u5c06\u88ab\u8fc7\u6ee4\uff0c\u4e0d\u6d89\u53ca\u5230\u7684\u5219\u4ecd\u7136\u6267\u884c\u3002\u4e3e\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre># \u4e3b\u5e93\u6267\u884c\uff1a\nbegin;\ninsert into db1.tb1 values(1);\ninsert into db2.tb2 values(2);\ncommit;\n# \u4ece\u5e93\u8bbe\u7f6e\nCHANGE REPLICATION FILTER REPLICATE_IGNORE_DB = (<strong>db1<\/strong>);\n# \u4ece\u5e93\u6267\u884c\u7684\u4e8b\u52a1\u53d8\u6210\u5982\u4e0b\uff1a\nbegin;\ninsert into db2.tb2 values(2);\ncommit;<\/pre>\n<p>\uff082\uff09\u5982\u679c\u4e8b\u52a1\u4e2d\u7684\u6240\u6709SQL\u90fd\u662f\u88ab\u8fc7\u6ee4\u7684\uff0c\u90a3\u4e48\u4ece\u5e93\u5c31\u4f1a\u53d8\u6210\u6267\u884c\u4e00\u4e2a\u7a7a\u4e8b\u52a1\u3002<\/p>\n<pre># \u4e3b\u5e93\u6267\u884c\uff1a\nbegin;\ninsert into\u00a0<strong>db1<\/strong>.tb1 values(1);\ninsert into\u00a0<strong>db1<\/strong>.tb2 values(2);\ncommit;\n# \u4ece\u5e93\u8bbe\u7f6e\nCHANGE REPLICATION FILTER REPLICATE_IGNORE_DB = (<strong>db1<\/strong>);\n# \u4ece\u5e93\u6267\u884c\u7684\u4e8b\u52a1\u53d8\u6210\u5982\u4e0b\uff1a\nbegin;\ncommit;<\/pre>\n<p>\uff083\uff09\u8fc7\u6ee4\u662f\u5168\u5c40\u8bbe\u7f6e\u7684\uff0c\u5982\u679c\u4f7f\u7528channel\u591a\u901a\u9053\u590d\u5236\uff0c\u90a3\u4e48\u6240\u6709\u901a\u9053\u7684\u590d\u5236\u8fc7\u6ee4\u90fd\u662f\u4e00\u6837\u7684\u3002MySQL 8.0 \u5bf9\u8fd9\u4e2a\u95ee\u9898\u8fdb\u884c\u4e86\u6539\u8fdb\uff0c\u80fd\u591f\u5bf9\u67d0\u4e2a\u901a\u9053\u5355\u72ec\u6307\u5b9a\u590d\u5236\u8fc7\u6ee4\u89c4\u5219\u3002<\/p>\n<h4>3. binlog_format\u4e3astatement<\/h4>\n<p>\u5bf9\u4e8ebinlog\u683c\u5f0f\u4e3astatement\u65f6\uff0c\u8fc7\u6ee4db\u7684\u903b\u8f91\u4e0erow\u683c\u5f0f\u4e0d\u592a\u4e00\u6837\uff0c\u5224\u65adsql\u662f\u5426\u5c5e\u4e8e\u67d0\u4e2adb\uff0c\u4e0euse db\u76f8\u5173\u3002\u6bd4\u5982\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u76ee\u7684\u662f\u60f3\u8981\u5c06\u6d89\u53cadb1\u7684SQL\u4e0d\u5199\u5165binlog\uff0c\u7ed3\u679c\u5374\u4e0e\u9884\u60f3\u4e0d\u4e00\u6837\u3002<\/p>\n<pre><strong># \u8bbe\u7f6e\uff1a<\/strong>\n--binlog-ignore-db=<strong>db1<\/strong>\n<strong># \u6267\u884cSQL\uff1a<\/strong>\nuse\u00a0<strong>db2<\/strong>;\nupdate\u00a0<strong>db1<\/strong>.tb set name=\\'123\\' where id=1;<\/pre>\n<p>\u5bf9db1\u4e2d\u7684\u8868\u505a\u4e86\u4fee\u6539\uff0c\u8be5\u4fee\u6539\u672c\u6765\u662f\u60f3\u5ffd\u7565\uff0c\u4e0d\u8bb0\u5f55binlog\uff0c\u4f46\u7ed3\u679c\u4ecd\u7136\u8bb0\u5f55\u5728binlog\u91cc\uff0c\u539f\u56e0\u5c31\u662fuse db2\u5bfc\u81f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL\u4e3b\u4ece\u590d\u5236\u662f\u903b\u8f91\u590d\u5236\uff0c\u57fa\u4e8eBinlog\u8fdb\u884c\u4e3b\u4ece\u6570\u636e\u4f20\u8f93\uff0cMySQL\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u53c2\u6570\u6765\u914d\u7f6e\u4e3b\u4ece\u590d\u5236\u8fc7\u6ee4\u6761 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=1502\"> <span class=\"screen-reader-text\">MySQL\u4e3b\u4ece\u590d\u5236\u6761\u4ef6\u8fc7\u6ee4<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[90,88],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"MySQL\u4e3b\u4ece\u590d\u5236\u662f\u903b\u8f91\u590d\u5236\uff0c\u57fa\u4e8eBinlog\u8fdb\u884c\u4e3b\u4ece\u6570\u636e\u4f20\u8f93\uff0cMySQL\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u53c2\u6570\u6765\u914d\u7f6e\u4e3b\u4ece\u590d\u5236\u8fc7\u6ee4\u6761&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1502"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1502"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/1502\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1502"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}