{"id":5386,"date":"2020-07-30T00:10:40","date_gmt":"2020-07-29T16:10:40","guid":{"rendered":"http:\/\/39.97.231.10\/?p=5386"},"modified":"2020-07-30T00:10:40","modified_gmt":"2020-07-29T16:10:40","slug":"mysql-binlog%e6%96%87%e4%bb%b6%e6%a0%bc%e5%bc%8f%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=5386","title":{"rendered":"MySQL Binlog\u6587\u4ef6\u683c\u5f0f\u89e3\u6790"},"content":{"rendered":"<div>\n<div>\n<div>\nMySQL\u901a\u8fc7Binlog\u8fdb\u884c\u4e3b\u4ece\u6570\u636e\u7684\u590d\u5236\uff0cBinlog\u662f\u4e00\u79cd\u4e8c\u8fdb\u5236\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u7406\u89e3Binlog\u4e8c\u8fdb\u5236\u683c\u5f0f\u80fd\u591f\u5e2e\u52a9\u6211\u4eec\u8fdb\u4e00\u6b65\u7406\u89e3MySQL\u7684\u4e3b\u4ece\u590d\u5236\u539f\u7406\u3002\u672c\u6587\u5c06\u5bf9Binlog\u6587\u4ef6\u683c\u5f0f\u8fdb\u884c\u5206\u6790\u3002<br \/>\n\u672c\u6587\u6d89\u53ca\u7684\u6e90\u7801\u7248\u672c\u548c\u76f8\u5173\u53c2\u6570\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>MySQL Server 5.7.19<\/li>\n<li>binlog_format\uff1aROW<\/li>\n<li>binlog_row_image\uff1aFULL<\/li>\n<\/ul>\n<h5>\u4e00\u3001Binlog\u6587\u4ef6Magic Number\uff1a<\/h5>\n<p>Binlog\u6587\u4ef6\uff0c\u524d4\u4e2a\u5b57\u8282\u56fa\u5b9a\u4e3a\u4e00\u4e2aMagic Number\uff0c\u5341\u516d\u8fdb\u5236\u503c\u4e3afe62696e\uff0c\u5982\u679c\u4e00\u4e2a\u6587\u4ef6\u5176\u524d4\u4e2a\u5b57\u8282\u4e0d\u662f\u8fd9\u4e2aMagic Number\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u8ba4\u4e3a\u5176\u4e0d\u662f\u4e00\u4e2a\u6709\u6548\u7684Binlog\u6587\u4ef6\u3002<\/p>\n<h5>\u4e8c\u3001Binlog event\uff1a<\/h5>\n<p>Binlog\u6587\u4ef6\u9664\u4e86\u6700\u524d\u9762\u76844\u4e2a\u5b57\u8282\u4e4b\u5916\uff0c\u5c31\u662f\u4e00\u4e2a\u4e00\u4e2a\u7684event\uff0cevent\u5305\u542b\u4e24\u4e2a\u90e8\u5206\uff0cevent header\u548cevent data\u3002\u901a\u5e38event header\u5927\u5c0f\u56fa\u5b9a\uff0cevent data\u5927\u5c0f\u53ef\u53d8\u3002<br \/>\nevent\u6574\u4f53\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<pre>+===================+\n| event header |\n+===================+\n| event data \u00a0|\n+===================+\n<\/pre>\n<p>event header \u548c event data \u8be6\u7ec6\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<pre>| ** event header **\u00a0|\n|\u00a0timestamp 0 : 4 |\n| type_code 4 : 1 |\n| server_id 5 : 4 |\n| event_length 9 : 4 |\n| next_position 13 : 4 |\n| flags 17 : 2 |\n| extra_headers 19 : x-19 |\n| ** event data\u00a0**|\u00a0\n| fixed part x : y |\n| variable part |\n<\/pre>\n<p>event header \u7ed3\u6784\u89e3\u6790\uff1a<\/p>\n<ul>\n<li>timestamp\uff1a\u65f6\u95f4\u6233\uff0c\u8868\u793a\u8be5event\u7684\u751f\u6210\u65f6\u95f4\uff0c\u5360\u75284\u4e2a\u5b57\u8282<\/li>\n<li>type_code\uff1aevent\u7c7b\u578b\uff0c\u5360\u75281\u4e2a\u5b57\u8282<\/li>\n<li>server_id\uff1a\u751f\u6210event\u7684server_id\uff0c\u5360\u75284\u4e2a\u5b57\u8282<\/li>\n<li>event_length\uff1aevent\u7684\u5927\u5c0f\uff0c\u5360\u75284\u4e2a\u5b57\u8282<\/li>\n<li>next_position:\u4e0b\u4e00\u4e2aevent\u7684\u4f4d\u7f6e\uff0c\u5360\u75284\u4e2a\u5b57\u8282<\/li>\n<li>flags\uff1aevent flags\uff0c\u5360\u75282\u4e2a\u5b57\u8282<\/li>\n<li>extra_headers\uff1a\u989d\u5916\u7684\u4fe1\u606f\uff0c\u5360\u7528\u7684\u5b57\u8282\u4e0d\u786e\u5b9a\uff0c\u4e5f\u53ef\u80fd\u6ca1\u6709\u3002\u7531event type\u4e3aFORMAT_DESCRIPTION_EVENT\u00a0\u7c7b\u578b\u7684event\u4e2d\u7684\u6570\u636e\u51b3\u5b9a\u3002<\/li>\n<\/ul>\n<p>event data\u7ed3\u6784\u89e3\u6790\uff1a<\/p>\n<ul>\n<li>fixed part\uff1a\u56fa\u5b9a\u7684\u90e8\u5206\uff0c\u6bcf\u4e00\u79cd\u7c7b\u578b\u7684event\uff0c\u5176fixed part\u90e8\u5206\u5360\u7528\u7684\u5927\u5c0f\u662f\u56fa\u5b9a\u7684\u3002\u5177\u4f53\u5927\u5c0f\u7531\u7c7b\u578b\u4e3a FORMAT_DESCRIPTION_EVENT \u7684event\u4e2d\u7684\u53ef\u53d8\u6570\u7ec4\u7684\u503c\u51b3\u5b9a\u3002<\/li>\n<li>variable part\uff1a\u53ef\u53d8\u7684\u90e8\u5206\uff0c\u8fd9\u90e8\u5206\u5927\u5c0f\u53ef\u53d8\uff0c\u5177\u4f53\u7531 event header \u4e2d\u7684event_length\u00a0\u51cf\u53bb\u00a0event header\u00a0\u7684\u5927\u5c0f\u00a0\u548c fixed part\u00a0\u90e8\u5206\u7684\u5927\u5c0f \u83b7\u5f97\u3002<\/li>\n<\/ul>\n<h5>\u4e09\u3001FORMAT_DESCRIPTION_EVENT\uff1a<\/h5>\n<p>\u524d\u9762\u63d0\u5230\u7c7b\u578b\u4e3aFORMAT_DESCRIPTION_EVENT\u7684event\uff0c\u8fd9\u4e2aevent\u6bd4\u8f83\u7279\u6b8a\uff0c\u901a\u5e38\u4e00\u4e2aBinlog\u6587\u4ef6\u53ea\u6709\u4e00\u4e2a\u8be5\u7c7b\u578b\u7684event\uff0c\u5e76\u4e14\u662fBinlog\u6587\u4ef6\u4e2d\u51fa\u73b0\u7684\u7b2c\u4e00\u4e2aevent\u3002\u8fd9\u4e2aevent\u5b58\u50a8\u7740\u975e\u5e38\u5173\u952e\u7684\u5143\u6570\u636e\u3002<br \/>\nFORMAT_DESCRIPTION_EVENT\u7c7b\u578b\u7684event\uff0c\u5176event header\u56fa\u5b9a\u4e3a19\u4e2a\u5b57\u8282\uff0c\u6ca1\u6709extra_headers\u90e8\u5206\u3002\u5176event data\u90e8\u5206\uff0c\u53ea\u5305\u542bfixed part\uff0c\u00a0\u6ca1\u6709variable part\u90e8\u5206\u3002<br \/>\nfixed part\u90e8\u5206\u5982\u4e0b:<\/p>\n<ul>\n<li>binlog\u00a0\u7248\u672c\u4fe1\u606f\uff1a\u5360\u75282\u4e2a\u5b57\u8282<\/li>\n<li>mysql server\u00a0\u7248\u672c\u4fe1\u606f\uff1a\u5360\u752850\u4e2a\u5b57\u8282<\/li>\n<li>timestamp\u00a0\u65f6\u95f4\u6233\uff1a\u5360\u75284\u4e2a\u5b57\u8282<\/li>\n<li>header length\uff1aevent header\u957f\u5ea6\uff0c\u5360\u75281\u4e2a\u5b57\u8282\uff0c\u5982\u679c\u4e3a19\uff0c\u8868\u793a\u6240\u6709\u7c7b\u578b\u7684event\uff0c\u5176event header\u7684extra_headers\u90e8\u5206\u90fd\u4e3a\u7a7a\u3002<\/li>\n<li>\u53ef\u53d8\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u5143\u7d20\u5360\u7528\u4e00\u4e2a\u5b57\u8282\uff0c\u6570\u7ec4\u5927\u5c0f\u4e0eevent\u7c7b\u578b\u6570\u91cf\u76f8\u540c\uff0c\u6bcf\u4e2a\u5143\u7d20\u8868\u793a\u8be5\u7c7b\u578b\u7684event\u00a0data\u00a0\u56fa\u5b9a\u90e8\u5206\uff08fixed part)\u5360\u7528\u7684\u5927\u5c0f\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7FORMAT_DESCRIPTION_EVENT event\u4e2d\u7684header length\u548c\u53ef\u53d8\u7684\u6570\u7ec4\uff0c\u5c31\u53ef\u4ee5\u786e\u5b9a\u6bcf\u4e2a\u7c7b\u578b\u7684event header\u5927\u5c0f\u548cfixed\u00a0part\u90e8\u5206\u7684\u5927\u5c0f\u3002\u4ece\u800c\u4e3a\u89e3\u6790\u6bcf\u4e2a\u7c7b\u578b\u7684event\u6253\u4e0b\u4e86\u57fa\u7840\u3002<\/p>\n<h5>\u56db\u3001event\u00a0\u7c7b\u578b\u6c47\u603b\uff1a<\/h5>\n<p>\u5206\u6790\u6e90\u7801\u6587\u4ef6 libbinlogevents\/include\/binlog_event.h \u4e2d\u7684\u679a\u4e3e\u7c7b\u578b Log_event_type\uff0c\u83b7\u53d6\u6240\u6709\u7684event\u7c7b\u578b\u5982\u4e0b\uff0c\u4e00\u517140\u4e2a\uff0c\u5e76\u4e0d\u662f\u6240\u6709\u7684\u7c7b\u578b\u90fd\u4f1a\u4f7f\u7528\uff0c\u6709\u4e00\u4e9b\u53ea\u662f\u517c\u5bb9\u4e4b\u524d\u7684\u7248\u672c\u3002<\/p>\n<ul>\n<li>UNKNOWN_EVENT= 0,<\/li>\n<li>START_EVENT_V3= 1,<\/li>\n<li>QUERY_EVENT= 2,<\/li>\n<li>STOP_EVENT= 3,<\/li>\n<li>ROTATE_EVENT= 4,<\/li>\n<li>INTVAR_EVENT= 5,<\/li>\n<li>LOAD_EVENT= 6,<\/li>\n<li>SLAVE_EVENT= 7,<\/li>\n<li>CREATE_FILE_EVENT= 8,<\/li>\n<li>APPEND_BLOCK_EVENT= 9,<\/li>\n<li>EXEC_LOAD_EVENT= 10,<\/li>\n<li>DELETE_FILE_EVENT= 11,<\/li>\n<li>NEW_LOAD_EVENT= 12,<\/li>\n<li>RAND_EVENT= 13,<\/li>\n<li>USER_VAR_EVENT= 14,<\/li>\n<li>FORMAT_DESCRIPTION_EVENT= 15,<\/li>\n<li>XID_EVENT= 16,<\/li>\n<li>BEGIN_LOAD_QUERY_EVENT= 17,<\/li>\n<li>EXECUTE_LOAD_QUERY_EVENT= 18,<\/li>\n<li>TABLE_MAP_EVENT = 19,<\/li>\n<li>PRE_GA_WRITE_ROWS_EVENT = 20,<\/li>\n<li>PRE_GA_UPDATE_ROWS_EVENT = 21,<\/li>\n<li>PRE_GA_DELETE_ROWS_EVENT = 22,<\/li>\n<li>WRITE_ROWS_EVENT_V1 = 23,<\/li>\n<li>UPDATE_ROWS_EVENT_V1 = 24,<\/li>\n<li>DELETE_ROWS_EVENT_V1 = 25,<\/li>\n<li>INCIDENT_EVENT= 26,<\/li>\n<li>HEARTBEAT_LOG_EVENT= 27,<\/li>\n<li>IGNORABLE_LOG_EVENT= 28,<\/li>\n<li>ROWS_QUERY_LOG_EVENT= 29,<\/li>\n<li>WRITE_ROWS_EVENT = 30,<\/li>\n<li>UPDATE_ROWS_EVENT = 31,<\/li>\n<li>DELETE_ROWS_EVENT = 32,<\/li>\n<li>GTID_LOG_EVENT= 33,<\/li>\n<li>ANONYMOUS_GTID_LOG_EVENT= 34,<\/li>\n<li>PREVIOUS_GTIDS_LOG_EVENT= 35,<\/li>\n<li>TRANSACTION_CONTEXT_EVENT= 36,<\/li>\n<li>VIEW_CHANGE_EVENT= 37,<\/li>\n<li>XA_PREPARE_LOG_EVENT= 38,<\/li>\n<li>ENUM_END_EVENT<\/li>\n<\/ul>\n<p>\u57fa\u672c\u4e0a\u6bcf\u79cd\u7c7b\u578b\u7684event\uff0c\u5176\u683c\u5f0f\u5404\u4e0d\u76f8\u540c\uff0c\u5fc5\u987b\u9488\u5bf9\u6bcf\u4e00\u79cd\u7c7b\u578b\u7684event\u8fdb\u884c\u89e3\u6790\uff0cMySQL\u6e90\u7801\u4e2d\u4e5f\u662f\u4e0d\u540c\u7684event\u90fd\u6709\u5176\u5bf9\u5e94\u7684c++\u7c7b\u8fdb\u884c\u89e3\u6790\u3002\n<\/p><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>MySQL\u901a\u8fc7Binlog\u8fdb\u884c\u4e3b\u4ece\u6570\u636e\u7684\u590d\u5236\uff0cBinlog\u662f\u4e00\u79cd\u4e8c\u8fdb\u5236\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u7406\u89e3Binlog\u4e8c\u8fdb\u5236\u683c\u5f0f\u80fd &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=5386\"> <span class=\"screen-reader-text\">MySQL Binlog\u6587\u4ef6\u683c\u5f0f\u89e3\u6790<\/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\u901a\u8fc7Binlog\u8fdb\u884c\u4e3b\u4ece\u6570\u636e\u7684\u590d\u5236\uff0cBinlog\u662f\u4e00\u79cd\u4e8c\u8fdb\u5236\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u7406\u89e3Binlog\u4e8c\u8fdb\u5236\u683c\u5f0f\u80fd&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5386"}],"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=5386"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5386\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5386"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}