{"id":4558,"date":"2013-11-25T22:47:36","date_gmt":"2013-11-25T14:47:36","guid":{"rendered":"http:\/\/ikiki.net\/?p=4558"},"modified":"2013-11-25T22:47:36","modified_gmt":"2013-11-25T14:47:36","slug":"use-mysql-replication-to-recove-binlog","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2013\/11\/use-mysql-replication-to-recove-binlog\/","title":{"rendered":"\u4f7f\u7528MySQL\u81ea\u8eab\u590d\u5236\u6765\u6062\u590dbinlog"},"content":{"rendered":"<p>\u5982\u679c\u9700\u8981\u6062\u590d\u7684\u4e8c\u8fdb\u5236\u65e5\u5fd7\u8f83\u591a\uff0c\u8f83\u590d\u6742\uff0c\u5f3a\u70c8\u5efa\u8bae\u4f7f\u7528MySQL\u81ea\u8eab\u590d\u5236\u6765\u6062\u590dbinlog\uff0c\u800c\u4e0d\u8981\u4f7f\u7528mysqlbinlog\u3002<\/p>\n\n<p>\u5728MySQL\u624b\u518c\u4e2d\u4e00\u76f4\u662f<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/point-in-time-recovery.html\" target=\"_blank\">\u63a8\u8350\u4f7f\u7528mysqlbinlog\u5de5\u5177<\/a>\u6765\u5b9e\u73b0\u6307\u5b9a\u65f6\u95f4\u70b9\u7684\u6570\u636e\u6062\u590d\uff0c\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u662f\u4e00\u4e2a\u7ecf\u5e38&#8221;\u8ba9\u4eba\u90c1\u95f7&#8221;\u7684\u529e\u6cd5\u3002\u66f4\u597d\u7684\u529e\u6cd5\u662f\uff0c\u4f7f\u7528MySQL\u5185\u90e8<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/replication-implementation.html\" target=\"_blank\">\u590d\u5236\u7ebf\u7a0b\u4e2d\u7684SQL Thread<\/a>\u6765\u505a\u6062\u590d\u3002<\/p>\n<p>\u8fd9\u4e2aidea\u6765\u81ea<a href=\"http:\/\/weibo.com\/lazydba\" target=\"_blank\">Lazydba<\/a>\u540c\u5b66\uff1b\u5728Google\u7a0d\u4f5c\u641c\u7d22\uff0c\u5728Xaprb\u4e0aBaron Schwartz\u4e5f\u5f88\u65e9\u63d0\u5230\u4e86\u4f7f\u7528\u7c7b\u4f3c\u7684\u65b9\u6cd5\u6765\u6062\u590dbinlog\uff0c\u5728<a href=\"http:\/\/www.xaprb.com\/blog\/2010\/09\/04\/why-mysql-replication-is-better-than-mysqlbinlog-for-recovery\/\" target=\"_blank\">\u90a3\u7bc7\u8ba8\u8bba<\/a>\u4e2d\uff0c\u8fd8\u53ef\u4ee5\u770b\u5230Jeremy Cole\u4e5f\u63d0\u5230\uff1a\u4f7f\u7528MySQL\u624b\u518c\u4e2d\u63a8\u8350\u7684\u65b9\u6cd5\u662f\u56f0\u96be\u91cd\u91cd\u7684\uff0c\u800c\u4e14mysqlbinlog\u8fd9\u4e2a\u529e\u6cd5\u4ece\u903b\u8f91\u4e0a\u6765\u8bf4\u4e5f\u662f\u4e00\u4e2a\u9519\u8bef&#8211;\u56e0\u4e3a\u8fd9\u6837MySQL\u4e0d\u5f97\u4e0d\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u5730\u65b9\u5b9e\u73b0\u4e00\u5957\u76f8\u540c\u7684\u903b\u8f91\uff0c\u6700\u7ec8\u96be\u514d\u4f1a\u51fa\u9519\u3002\u4f7f\u7528mysqlbinlog\u6765\u6062\u590d\uff0c\u4f60\u53ef\u80fd\u4f1a\u9700\u8981\u4ee5\u4e0b\u201c\u8ba9\u4eba\u90c1\u95f7\u201d\u7684\u95ee\u9898\uff1a<\/p>\n<pre><blockquote>(*) Max_allowed_packet\u95ee\u9898\r\n(*) \u607c\u4eba\u7684Blob\/Binary\/text\u5b57\u6bb5\u95ee\u9898\r\n(*) \u7279\u6b8a\u5b57\u7b26\u7684\u8f6c\u4e49\u95ee\u9898\r\n(*) \u6ca1\u6709\"\u65ad\u70b9\u6062\u590d\"\uff1a\u6267\u884c\u51fa\u9519\u540e\uff0c\u6ca1\u6709\u8db3\u591f\u7684\u62a5\u9519\uff0c\u4e5f\u5f88\u96be\u4ece\u5931\u8d25\u7684\u5730\u65b9\u7ee7\u7eed\u6062\u590d<\/blockquote><\/pre>\n<h3>1. \u5982\u4f55\u64cd\u4f5c<\/h3>\n<p>\u672c\u6587\u4e0d\u6253\u7b97\u5199\u4e00\u4e2astep by step\u7684\u6587\u6863\uff0c\u53ea\u4ecb\u7ecd\u4e3b\u8981\u7684\u601d\u8def\u548c\u7c97\u7565\u7684\u64cd\u4f5c\u6b65\u9aa4\u3002<\/p>\n<h4>1.1 \u5c06binlog\u4f5c\u4e3arelay log\u6765\u6267\u884c<\/h4>\n<p>\u4f18\u70b9\uff1a\u5b9e\u65bd\u7b80\u5355\uff1b\u7f3a\u70b9\uff1a\u9700\u8981\u5173\u95ed\u4e00\u6b21\u6570\u636e\u5e93(\u4e0d\u786e\u5b9a\u4e0d\u5173\u95ed\u6570\u636e\u5e93\u884c\u4e0d\u884c)\uff1b<\/p>\n<p>\u601d\u8def\uff1a\u76f4\u63a5\u5c06\u8981\u6062\u590d\u7684binlog\u62f7\u8d1d\u5230relay log\u76ee\u5f55\uff0c\u5e76\u4fee\u6539slave-info\u76f8\u5173\u7684\u6587\u4ef6\uff0c\u8ba9MySQL\u628abinlog\u5f53\u505arelay log\u6765\u6267\u884c<\/p>\n<p>\u7b80\u5355\u7684\u64cd\u4f5c\u6b65\u9aa4\uff1a<!--more--><\/p>\n<pre><blockquote>* \u5173\u95ed\u5f53\u524d\u5b9e\u4f8b\r\n* \u5c06binlog\u62f7\u8d1d\u5230\u5bf9\u5e94\u7684relay log\u76ee\u5f55(datadir\u6216\u8005relay-log\u53c2\u6570\u6307\u5b9a\u7684\u76ee\u5f55)\r\n* <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/slave-logs-status.html\" target=\"_blank\">\u6253\u5f00relay-log-info-file\u53c2\u6570\u6307\u5b9a\u7684relay-log.info\u6587\u4ef6<\/a>(\u9ed8\u8ba4\u662fdatadir\u76ee\u5f55\u4e0b\u7684relay-log.info\u6587\u4ef6)\uff0c\u4fee\u6539\u6587\u4ef6\u524d\u9762\u4e24\u884c\u3002\r\n\u8fd9\u4e24\u884c\u7684\u610f\u4e49\u5206\u522b\u662f\uff1a\u5f53\u524d\u6267\u884c\u7684relay log\u6587\u4ef6\uff1b\u5f53\u524d\u6267\u884c\u5230relay log\u6587\u4ef6\u7684\u4f4d\u7f6e(position)\r\n* \u6253\u5f00relay-log-index\u6587\u4ef6(\u7531\u53c2\u6570--relay-log-index\uff0c\u9ed8\u8ba4\u662f\u6570\u636e\u76ee\u5f55\u4e0b\u7684host_name-relay-bin.index)\u5c06\u9700\u8981\u6062\u590d\u7684binlog\u6587\u4ef6\u5168\u8def\u5f84\u5217\u8868\u5b58\u5728\u8be5\u6587\u4ef6\u4e2d\r\n* \u542f\u52a8\u6570\u636e\u5e93\uff0c\u5e76start slave io_thread<\/blockquote><\/pre>\n<h4>1.2 \u4ece\u4e13\u95e8\u6784\u5efa\u7684binlog server\u4e0a\u62c9binlog<\/h4>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u65e0\u9700\u542f\u52a8\u6570\u636e\u5e93\uff0c\u4f46\u662f\u9700\u8981\u91cd\u65b0\u542f\u52a8\u4e00\u4e2a\u5168\u65b0\u7684\u5b9e\u4f8b\uff0c\u5c06binlog\u62f7\u8d1d\u5230\u8be5\u5b9e\u4f8b\u4e2d\uff0c\u8fd9\u91cc\u79f0\u8fd9\u4e2a\u5b9e\u4f8b\u4e3abinlog server\u3002\u7136\u540e\u628a\u9700\u8981\u6062\u590d\u7684\u5b9e\u4f8b\u590d\u5236\u6307\u5411\u8fd9\u4e2abinlog server\u3002\u8fd9\u91cc\u9700\u8981\u505a\u7684\u662f\uff0c\u5c06\u65e5\u5fd7\u62f7\u8d1d\u5230binlog server\u5bf9\u5e94\u76ee\u5f55\u4e0b\uff0c\u5e76\u4fee\u6539\u5bf9\u5e94\u7684master-info\u6587\u4ef6\uff0c\u4f7f\u5f97\u5907\u5e93\u80fd\u591fdump\u5230\u8fd9\u4e9bbinlog\u6587\u4ef6\u3002<\/p>\n<h3>2. \u5176\u4ed6\u9700\u8981\u6ce8\u610f\u7684\u4e8b\u9879<\/h3>\n<p>* \u914d\u7f6e\u6587\u4ef6\u4e2d\u5efa\u8bae\u52a0\u4e0a<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/replication-options-slave.html#option_mysqld_skip-slave-start\" target=\"_blank\">skip-slave-start<\/a>\uff0c\u4ee5\u514d\u5728\u4e0d\u9700\u8981\u65f6\u5019slave\u7ebf\u7a0b\u81ea\u5df1\u5f00\u59cb\u6267\u884c\u4e86<\/p>\n<p>* start slave\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u901a\u8fc7start slave until\u7684\u65b9\u5f0f\uff0c\u63a7\u5236slave\u6267\u884c\u5230\u7684\u4f4d\u70b9<\/p>\n<p>* slave\u6267\u884c\u7684\u5176\u5b9e\u4f4d\u70b9\uff0c\u5219\u901a\u8fc7relay-log.info\u6216\u8005change master to\u6765\u6307\u5b9a<\/p>\n<p>Good Luck.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u9700\u8981\u6062\u590d\u7684\u4e8c\u8fdb\u5236\u65e5\u5fd7\u8f83\u591a\uff0c\u8f83\u590d\u6742\uff0c\u5f3a\u70c8\u5efa\u8bae\u4f7f\u7528MySQL\u81ea\u8eab\u590d\u5236\u6765\u6062\u590dbinlog\uff0c\u800c\u4e0d\u8981\u4f7f\u7528mysqlbinlog\u3002 \u5728MySQL\u624b\u518c\u4e2d\u4e00\u76f4\u662f\u63a8\u8350\u4f7f\u7528mysqlbinlog\u5de5\u5177\u6765\u5b9e\u73b0\u6307\u5b9a\u65f6\u95f4\u70b9\u7684\u6570\u636e\u6062\u590d\uff0c\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u662f\u4e00\u4e2a\u7ecf\u5e38&#8221;\u8ba9\u4eba\u90c1\u95f7&#8221;\u7684\u529e\u6cd5\u3002\u66f4\u597d\u7684\u529e\u6cd5\u662f\uff0c\u4f7f\u7528MySQL\u5185\u90e8\u590d\u5236\u7ebf\u7a0b\u4e2d\u7684SQL Thread\u6765\u505a\u6062\u590d\u3002 \u8fd9\u4e2aidea\u6765\u81eaLazydba\u540c\u5b66\uff1b\u5728Google\u7a0d\u4f5c\u641c\u7d22\uff0c\u5728Xaprb\u4e0aBaron Schwartz\u4e5f\u5f88\u65e9\u63d0\u5230\u4e86\u4f7f\u7528\u7c7b\u4f3c\u7684\u65b9\u6cd5\u6765\u6062\u590dbinlog\uff0c\u5728\u90a3\u7bc7\u8ba8\u8bba\u4e2d\uff0c\u8fd8\u53ef\u4ee5\u770b\u5230Jeremy Cole\u4e5f\u63d0\u5230\uff1a\u4f7f\u7528MySQL\u624b\u518c\u4e2d\u63a8\u8350\u7684\u65b9\u6cd5\u662f\u56f0\u96be\u91cd\u91cd\u7684\uff0c\u800c\u4e14mysqlbinlog\u8fd9\u4e2a\u529e\u6cd5\u4ece\u903b\u8f91\u4e0a\u6765\u8bf4\u4e5f\u662f\u4e00\u4e2a\u9519\u8bef&#8211;\u56e0\u4e3a\u8fd9\u6837MySQL\u4e0d\u5f97\u4e0d\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u5730\u65b9\u5b9e\u73b0\u4e00\u5957\u76f8\u540c\u7684\u903b\u8f91\uff0c\u6700\u7ec8\u96be\u514d\u4f1a\u51fa\u9519\u3002\u4f7f\u7528mysqlbinlog\u6765\u6062\u590d\uff0c\u4f60\u53ef\u80fd\u4f1a\u9700\u8981\u4ee5\u4e0b\u201c\u8ba9\u4eba\u90c1\u95f7\u201d\u7684\u95ee\u9898\uff1a (*) Max_allowed_packet\u95ee\u9898 (*) \u607c\u4eba\u7684Blob\/Binary\/text\u5b57\u6bb5\u95ee\u9898 (*) \u7279\u6b8a\u5b57\u7b26\u7684\u8f6c\u4e49\u95ee\u9898 (*) \u6ca1\u6709&#8221;\u65ad\u70b9\u6062\u590d&#8221;\uff1a\u6267\u884c\u51fa\u9519\u540e\uff0c\u6ca1\u6709\u8db3\u591f\u7684\u62a5\u9519\uff0c\u4e5f\u5f88\u96be\u4ece\u5931\u8d25\u7684\u5730\u65b9\u7ee7\u7eed\u6062\u590d 1. \u5982\u4f55\u64cd\u4f5c \u672c\u6587\u4e0d\u6253\u7b97\u5199\u4e00\u4e2astep by step\u7684\u6587\u6863\uff0c\u53ea\u4ecb\u7ecd\u4e3b\u8981\u7684\u601d\u8def\u548c\u7c97\u7565\u7684\u64cd\u4f5c\u6b65\u9aa4\u3002 1.1 \u5c06binlog\u4f5c\u4e3arelay log\u6765\u6267\u884c \u4f18\u70b9\uff1a\u5b9e\u65bd\u7b80\u5355\uff1b\u7f3a\u70b9\uff1a\u9700\u8981\u5173\u95ed\u4e00\u6b21\u6570\u636e\u5e93(\u4e0d\u786e\u5b9a\u4e0d\u5173\u95ed\u6570\u636e\u5e93\u884c\u4e0d\u884c)\uff1b \u601d\u8def\uff1a\u76f4\u63a5\u5c06\u8981\u6062\u590d\u7684binlog\u62f7\u8d1d\u5230relay log\u76ee\u5f55\uff0c\u5e76\u4fee\u6539slave-info\u76f8\u5173\u7684\u6587\u4ef6\uff0c\u8ba9MySQL\u628abinlog\u5f53\u505arelay log\u6765\u6267\u884c \u7b80\u5355\u7684\u64cd\u4f5c\u6b65\u9aa4\uff1a<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[6],"tags":[118],"class_list":["post-4558","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/4558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=4558"}],"version-history":[{"count":18,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/4558\/revisions"}],"predecessor-version":[{"id":4721,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/4558\/revisions\/4721"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=4558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=4558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=4558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}