{"id":259,"date":"2013-07-24T18:56:35","date_gmt":"2013-07-24T10:56:35","guid":{"rendered":"http:\/\/www.gpfeng.com\/?p=259"},"modified":"2017-03-24T11:20:26","modified_gmt":"2017-03-24T03:20:26","slug":"mysql-binlog%e5%ad%97%e7%ac%a6%e7%bc%96%e7%a0%81%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"http:\/\/www.gpfeng.com\/?p=259","title":{"rendered":"MySQL binlog\u5b57\u7b26\u7f16\u7801\u65b9\u5f0f"},"content":{"rendered":"<h3>\u95ee\u9898\u80cc\u666f<\/h3>\n<p>\u5e0c\u671b\u6839\u636eMySQL binlog\u56de\u6eda\u5df2\u7ecf\u63d0\u4ea4\u7684\u4e8b\u52a1\uff0c\u4e00\u4e2a\u91cd\u8981\u7684\u5e94\u7528\u573a\u666f\uff1a\u56de\u6eda\u8bef\u64cd\u4f5c\uff0c\u6dd8\u5b9d\u667a\u80dc\u5728\u8fd9\u65b9\u9762\u505a\u4e86\u5f88\u591a\u5de5\u4f5c\uff0c\u8be6\u60c5\u53c2\u8003<a href=http:\/\/os.51cto.com\/art\/201212\/370444.htm>\u5229\u7528MySQL\u65e5\u5fd7\u6a21\u62df\u6062\u590d\u6570\u636e\u53d8\u5316\u8f68\u8ff9<\/a>, <a href=http:\/\/os.51cto.com\/art\/201212\/370445.htm>\u5229\u7528MySQL\u65e5\u5fd7\u6a21\u62df\u6062\u590d\u6570\u636e\u53d8\u5316\u8f68\u8ff9II<\/a>\uff0c\u6700\u8fd1\u9047\u5230\u4e86\u4e00\u4e9b\u5b57\u7b26\u96c6\u76f8\u5173\u95ee\u9898\uff0c\u56de\u6eda\u5931\u8d25\u3002\u8fd9\u7bc7\u6587\u7ae0\u65e8\u5728\u5206\u6790MySQl binlog\u4e2d\u4e0e\u8868\u64cd\u4f5c\u76f8\u5173\u7684\u5b57\u7b26\u96c6\u3002<\/p>\n<h3>\u5b9e\u9a8c\u6d4b\u8bd5\uff1a<\/h3>\n<p>a) \u7cfb\u7edf\u5b57\u7b26\u96c6\uff0c\u4fdd\u8bc1\u80fd\u591f\u652f\u6301\u4e2d\u6587<\/p>\n<pre lang=\"shell\">\r\n$echo $LANG\r\nen_US.UTF-8\r\n<\/pre>\n<p><!--more--><br \/>\nb) \u5b9a\u4e49\u4e00\u4e2a\u5305\u542b\u4e24\u4e2a\u5b57\u7b26\u96c6\u4e0d\u540c\uff08UTF8\u4e0eGBK\uff09\u7684\u5217\u7684\u8868<\/p>\n<pre lang=\"mysql\">\r\nmysql> show create table charset_test\\G\r\n*************************** 1. row ***************************\r\n       Table: charset_test\r\nCreate Table: CREATE TABLE `charset_test` (\r\n  `utf8` varchar(32) CHARACTER SET utf8 DEFAULT NULL,\r\n  `gbk` varchar(32) DEFAULT NULL\r\n) ENGINE=InnoDB DEFAULT CHARSET=gbk\r\n1 row in set (0.00 sec)\r\n\r\nmysql> flush logs;\r\nQuery OK, 0 rows affected (0.00 sec)\r\n\r\nmysql> insert into charset_test values('UTF8\u5b57\u7b26\u4e32', 'GKB\u5b57\u7b26\u4e32');\r\nQuery OK, 1 row affected (0.00 sec)\r\n\r\nmysql> show master status\\G\r\n*************************** 1. row ***************************\r\n            File: mysql-bin.000008\r\n        Position: 312\r\n    Binlog_Do_DB:\r\nBinlog_Ignore_DB:\r\n1 row in set (0.00 sec)\r\n<\/pre>\n<p>c) \u7528mysqlbinlog\u5de5\u5177\u67e5\u770b\u4e0a\u8ff0INSERT\u8bed\u53e5\u4ea7\u751f\u7684binlog\uff1a<\/p>\n<pre lang=\"shell\">\r\n$bin\/mysqlbinlog -vvv log\/mysql-bin.000008>\/tmp\/binlog\r\n$cat \/tmp\/binlog\r\n<\/pre>\n<pre lang=\"mysql\">\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n# at 107\r\n#130724 17:39:59 server id 1  end_log_pos 175   Query   thread_id=2     exec_time=0     error_code=0\r\nSET TIMESTAMP=1374658799\/*!*\/;\r\nSET @@session.pseudo_thread_id=2\/*!*\/;\r\nSET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1\/*!*\/;\r\nSET @@session.sql_mode=0\/*!*\/;\r\nSET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1\/*!*\/;\r\n\/*!\\C utf8 *\/\/*!*\/;\r\nSET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=28\/*!*\/;\r\nSET @@session.lc_time_names=0\/*!*\/;\r\nSET @@session.collation_database=DEFAULT\/*!*\/;\r\nBEGIN\r\n\/*!*\/;\r\n# at 175\r\n# at 231\r\n#130724 17:39:59 server id 1  end_log_pos 231   Table_map: `test`.`charset_test` mapped to number 35\r\n#130724 17:39:59 server id 1  end_log_pos 285   Write_rows: table id 35 flags: STMT_END_F\r\n\r\nBINLOG '\r\n76DvURMBAAAAOAAAAOcAAAAAACMAAAAAAAEABHRlc3QADGNoYXJzZXRfdGVzdAACDw8EYABAAAM=\r\n76DvURcBAAAANgAAAB0BAAAAACMAAAAAAAEAAv\/8DVVURjjlrZfnrKbkuLIJR0tC19a3+7Su\r\n'\/*!*\/;\r\n### INSERT INTO test.charset_test\r\n### SET\r\n###   @1='UTF8\u5b57\u7b26\u4e32' \/* VARSTRING(96) meta=96 nullable=1 is_null=0 *\/\r\n###   @2='GKB' \/* VARSTRING(64) meta=64 nullable=1 is_null=0 *\/\r\n# at 285\r\n#130724 17:39:59 server id 1  end_log_pos 312   Xid = 31\r\nCOMMIT\/*!*\/;\r\nDELIMITER ;\r\n# End of log file\r\nROLLBACK \/* added by mysqlbinlog *\/;\r\n\/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*\/;\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n<\/pre>\n<p>d) \u8fd9\u91cc\u53ea\u5173\u5fc3row\u6a21\u5f0fbinlog\u5bf9\u5e94\u7684insert\u8bed\u53e5\uff1a<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.gpfeng.com\/wp-content\/uploads\/2013\/07\/chaset_test_1.png\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.gpfeng.com\/wp-content\/uploads\/2013\/07\/chaset_test_1.png?w=660\" alt=\"chaset_test_1\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>e) \u53d1\u73b0@2\uff08\u5217`gbk`\uff09\u6ca1\u6709\u663e\u793a\u5168\uff08\u4e71\u7801\uff1f\uff09\uff0c\u9042\u4ee516\u8fdb\u5236\u65b9\u5f0f\u67e5\u770b\u8fd9\u90e8\u5206\u5b8c\u6574\u4fe1\u606f<\/p>\n<pre lang=\"shell\">$hexdump -C \/tmp\/binlog<\/pre>\n<p><a href=\"https:\/\/i0.wp.com\/www.gpfeng.com\/wp-content\/uploads\/2013\/07\/chaset_test_2.png\"><img decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.gpfeng.com\/wp-content\/uploads\/2013\/07\/chaset_test_2.png?w=660\" alt=\"chaset_test_2\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>&#8216;<strong>UTF8\u5b57\u7b26\u4e32<\/strong>&#8216;\u4e2d&#8217;<strong>\u5b57\u7b26\u4e32<\/strong>&#8216;\u4e09\u4e2a\u5b57\u5728\u53f3\u8fb9\u663e\u793a\u4e3a&#8217;&#8230;&#8230;&#8230;&#8217;\uff0c\u5176\u5bf9\u5e94\u768416\u8fdb\u5236\u4e3ae5ad97 e7aca6 e4b8b2\uff0c\u4e3a\u5565\u6bcf\u9694\u4e09\u4e2a\u5b57\u7b26\u9694\u5f00\uff1f\u67e5\u770b&#8217;\u5b57\u7b26\u4e32&#8217;\u7684<a href=http:\/\/www.mytju.com\/classcode\/tools\/urlencode_utf8.asp>UTF\u7f16\u7801<\/a>\uff0c\u53d1\u73b0\u6b63\u597d\u662f\uff1a<\/p>\n<p>\u5b57->E5AD97<br \/>\n\u7b26->E7ACA6<br \/>\n\u4e32->E4B8B2<\/p>\n<p>\u8bc1\u5b9e\u4e86\u5176\u7684\u786e\u662fUTT8\u7f16\u7801\uff0c\u800c&#8217;<strong>GBK\u5b57\u7b26\u4e32<\/strong>&#8216;\u4e2d&#8217;<strong>\u5b57\u7b26\u4e32<\/strong>&#8216;\u4e09\u4e2a\u4e2d\u6587\u901a\u8fc7<a href=http:\/\/www.mytju.com\/classcode\/tools\/urlencode_gb2312.asp>GBK\u7f16\u7801<\/a>\u67e5\u770b(GBK\u5411\u4e0b\u517c\u5bb9GB2312\uff0c\u4e00\u4e2a\u4e2d\u6587\u7684GB2312\u7f16\u7801\u4e00\u5b9a\u4e0e\u5176GBK\u7f16\u7801\u76f8\u540c\uff09\uff0c\u4e5f\u6b63\u597d\u662f\u4e00\u4e00\u5bf9\u5e94\uff1a<\/p>\n<p>\u5b57->D7D6<br \/>\n\u7b26->B7FB<br \/>\n\u4e32->B4AE<\/p>\n<p>\u81f3\u6b64\uff0c\u5206\u6790\u7ed3\u675f\uff0c\u540e\u7eed\u95ee\u9898\u89e3\u51b3\u65b9\u6848\uff0c\u5f85\u7eed&#8230;<\/p>\n<h3>\u603b\u7ed3\uff1a<\/h3>\n<p>ROW\u6a21\u5f0fbinlog\u4e2d\u6587\u4ef6\uff0c&#8217;###&#8217;\u5f00\u5934\u7684INSERT\/DELETE\/UPDATE\u8bed\u53e5\u4e2d\u7684\u5404\u4e2a\u5217\u7684\u5b57\u7b26\u4e32\u7f16\u7801\u65b9\u5f0f\u4e0e\u5176\u5728\u8868\u4e2d\u5b9a\u4e49\uff08\u5b58\u50a8\uff09\u7684\u7f16\u7801\u65b9\u5f0f\u4e00\u81f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u80cc\u666f \u5e0c\u671b\u6839\u636eMySQL binlog\u56de\u6eda\u5df2\u7ecf\u63d0\u4ea4\u7684\u4e8b\u52a1\uff0c\u4e00\u4e2a\u91cd\u8981\u7684\u5e94\u7528\u573a\u666f\uff1a\u56de\u6eda\u8bef\u64cd\u4f5c\uff0c\u6dd8\u5b9d\u667a\u80dc\u5728\u8fd9\u65b9\u9762 &hellip; <a href=\"http:\/\/www.gpfeng.com\/?p=259\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">MySQL binlog\u5b57\u7b26\u7f16\u7801\u65b9\u5f0f<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3tPZp-4b","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/259"}],"collection":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=259"}],"version-history":[{"count":17,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/259\/revisions"}],"predecessor-version":[{"id":706,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/259\/revisions\/706"}],"wp:attachment":[{"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=259"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gpfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}