{"id":2166,"date":"2010-12-02T03:09:54","date_gmt":"2010-12-01T19:09:54","guid":{"rendered":"http:\/\/www.orczhou.com\/?p=2166"},"modified":"2010-12-02T03:10:44","modified_gmt":"2010-12-01T19:10:44","slug":"more-about-mysql-innodb-shutdown","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2010\/12\/more-about-mysql-innodb-shutdown\/","title":{"rendered":"\u4e5f\u8bf4\u5feb\u901f\u5173\u95edMySQL\/InnoDB"},"content":{"rendered":"<p>\u5982\u679c\u7528\u7684\u5f15\u64ce\u662fInnoDB\uff0c\u6bcf\u6b21\u6572\u4e0bmysqladmin -uroot -p shutdown\u5173\u95ed\u6570\u636e\u5e93\u7684\u65f6\u5019\uff0c\u603b\u662f\u5f88\u96be\u9884\u6d4b\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u6267\u884c\u591a\u4e45\uff0c\u5b9e\u9645\u7ecf\u9a8c\u8868\u660e\uff0c\u77ed\u5219\u4e94\u79d2\uff0c\u957f\u5219\u4e09\u5341\u5206\u949f\u4e00\u5c0f\u65f6\u90fd\u6709\u53ef\u80fd\u3002\u4e5f\u5206\u4eab\u4e00\u4e0b\u6211\u7684\u7ecf\u9a8c\u5427\u3002<\/p>\n<div class=\"myt1\">1. \u4e3a\u4ec0\u4e48InnoDB\u5173\u95ed\u4f1a\u6162\uff1f<\/div>\n<p>\u4e8b\u5b9e\u4e0a\uff0c\u5e76\u4e0d\u662f\u6bcf\u6b21\u5173\u95edInnoDB\u90fd\u5f88\u6162\u7684\u3002Why\uff1fInnoDB\u8f83\u4e4bMyISAM\uff0c\u4e00\u4e2a\u91cd\u8981\u7279\u6027\u662fInnoDB\u4f1a\u5728\u5185\u5b58\u4e2d\u5f00\u8f9f\u4e00\u4e2a<a href=\"http:\/\/www.orczhou.com\/index.php\/2009\/08\/innodb-dirty-page-redo-log-2\/\">Buffer Pool<\/a>\u6765\u5b58\u50a8\u6700\u8fd1\u8bbf\u95ee\u7684\u6570\u636e\u5757\/\u7d22\u5f15\u5757\uff0c\u4f7f\u5f97\u4e0b\u6b21\u518d\u6b21\u8bbf\u95ee\u8fd9\u4e2a\u5757\u65f6\u901f\u5ea6\u80fd\u591f\u5f88\u5feb\u3002\u5f53InnoDB\u5bf9\u9700\u8981\u4fee\u6539\u6570\u636e\u5757\u7684\u65f6\u5019\uff0c\u4f1a\u5148\u8bb0\u5f55\u4fee\u6539\u65e5\u5fd7\uff0c\u7136\u540e\u76f4\u63a5\u5bf9Buffer_Pool\u4e2d\u7684\u6570\u636e\u5757\u7684\u64cd\u4f5c\u3002\u8bb0\u5f55\u65e5\u5fd7\u662f\u987a\u5e8f\u5199\uff0c\u5bf9\u6570\u636e\u5757\u7684\u64cd\u4f5c\u662f\u5185\u5b58\u64cd\u4f5c\uff0c\u8fd9\u8ba9InnoDB\u5728\u5f88\u591a\u573a\u666f\u4e0b\u6709\u8fd9\u5f88\u597d\u7684\u901f\u5ea6\u4f18\u52bf\u3002<!--more--><\/p>\n<p>\u4e0a\u9762\u5bf9\u5185\u5b58\u5757\u4fee\u6539\u5b8c\u6210\u540e\uff0cInnoDB\u5c31\u5411\u5ba2\u6237\u7aef\u8fd4\u56de\u4e86\u3002\u53ef\u8fd9\u65f6\u5b9e\u9645\u78c1\u76d8\u4e0a\u7684\u6570\u636e\u5757\uff0c\u8fd8\u5e76\u6ca1\u6709\u88ab\u66f4\u65b0\uff0c\u6211\u4eec\u628a\u8fd9\u6837\u7684page\u79f0\u4e3a<a href=\"http:\/\/www.orczhou.com\/index.php\/2009\/08\/innodb-dirty-page-redo-log-2\/\">Dirty Page<\/a>\u3002\u5728InnoDB\u7684\u540e\u53f0\u6709\u4e00\u4e2a\u4e13\u95e8\u7684\u7ebf\u7a0b\u6765\u505a\u5c06\u5185\u5b58\u6570\u636e\u5757Flush\u5230\u78c1\u76d8\u7684\u5de5\u4f5c\u3002\u8fd9\u4e2aFlush\u64cd\u4f5c\u5c31\u662f\u4e3b\u8981\u5f71\u54cdInnoDB\u5173\u95ed\u65f6\u95f4\u7684\u56e0\u7d20\u3002\u5728\u5173\u95edMySQL\/InnoDB\u65f6\uff0c\u6240\u6709\u7684Dirty_Page\u90fd\u9700\u8981Flush\uff0c<strong>\u6240\u4ee5Dirty_Page\u8d8a\u591a\uff0c\u8981Flush\u7684\u6570\u636e\u5757\u4e5f\u5c31\u8d8a\u591a\uff0c\u610f\u5473\u7740InnoDB\u5173\u95ed\u65f6\u95f4\u8d8a\u957f<\/strong>\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u547d\u4ee4\u6765\u89c2\u5bdfDirty Page\u7684\u6570\u91cf\uff1a<\/p>\n<div class=\"mycode\">mysqladmin -uroot ext -i 1 |grep &#8220;Innodb_buffer_pool_pages_dirty&#8221; <\/div>\n<div class=\"myt1\">2. \u53c2\u6570innodb_max_dirty_pages_pct<\/div>\n<p>Buffer_Pool\u4e2dDirty_Page\u6240\u5360\u7684\u6570\u91cf\uff0c\u76f4\u63a5\u5f71\u54cdInnoDB\u7684\u5173\u95ed\u65f6\u95f4\u3002\u53c2\u6570innodb_max_dirty_pages_pct\u53ef\u4ee5\u76f4\u63a5\u63a7\u5236\u4e86Dirty_Page\u5728Buffer_Pool\u4e2d\u6240\u5360\u7684\u6bd4\u7387\uff0c\u800c\u4e14\u5e78\u8fd0\u7684\u662finnodb_max_dirty_pages_pct\u662f\u53ef\u4ee5\u52a8\u6001\u6539\u53d8\u7684\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u5728\u5173\u95edInnoDB\u4e4b\u524d\u5148\u5c06innodb_max_dirty_pages_pct\u8c03\u5c0f\uff0c\u5f3a\u5236\u6570\u636e\u5757Flush\u4e00\u6bb5\u65f6\u95f4\uff0c\u5219\u80fd\u591f\u5927\u5927\u7f29\u77edMySQL\u5173\u95ed\u7684\u65f6\u95f4\u3002<\/p>\n<div class=\"mycode\">set global innodb_max_dirty_pages_pct=0;<\/div>\n<p>\u4e00\u822c\u6267\u884c\u4e86\u4e0a\u9762\u7684\u547d\u4ee4\u4e4b\u540e\uff0cDirty_Page\u7684Flush\u4ecd\u9700\u8981\u4e00\u6bb5\u65f6\u95f4\uff0c\u6240\u4ee5\u8981\u7a0d\u7b49\u4e00\u4f1a\u513f\uff0c\u518d\u5173\u95edMySQL\u624d\u6709\u6548\u679c\u3002<\/p>\n<div class=\"myt1\">3. \u5173\u95ed\u524d\u505a\u4e9b\u4ec0\u4e48<\/div>\n<p>\u6709\u65f6\u5019\uff0c\u5c31\u7b97\u4f60\u6539\u53d8innodb_max_dirty_pages_pct=0\uff0c\u4ecd\u7136\u4e0d\u80fd\u4fdd\u8bc1InnoDB\u5feb\u901f\u5173\u95ed\u3002\u8fd8\u6709\u4e00\u4e9b\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<p>\u8bbe\u7f6e\u6570\u636e\u5e93\u4e3a\u53ea\u8bfb\uff1a\u5982\u679c\u6570\u636e\u5e93\u4e00\u76f4\u662f\u6d3b\u8dc3\u7684\uff0c\u6709\u8fde\u63a5\u5728\u5411\u91cc\u9762\u5199\u6570\u636e\uff0c\u90a3\u4e48Dirty Page\u5219\u8fd8\u53ef\u80fd\u4e0d\u65ad\u7684\u4ea7\u751f\u3002<\/p>\n<p>\u5982\u679c\u662f\u5907\u5e93\uff0c\u5728innodb_max_dirty_pages_pct\u8bbe\u7f6e\u62100\u7684\u540c\u65f6\uff0c\u6700\u597d\u5148stop slave\uff1a\u8fd9\u4e2a\u5f88\u5173\u952e\uff0c\u800c\u4e14\u5bf9\u5173\u95ed\u65f6\u95f4\u5f71\u54cd\u4e5f\u4f1a\u5f88\u5927\u3002\u7b2c\u4e00\uff0c\u4e3b\u52a8stop slave\u540e\uff0cMySQL\u5728\u5173\u95ed\u65f6\uff0c\u9700\u8981\u505c\u6b62\u7684\u7ebf\u7a0b\u5176\u5b9e\u662f\u66f4\u5c11\u4e86\u7684\u3002\u7b2c\u4e8c\uff0c\u5982\u679cslave\u7684SQL\u7ebf\u7a0b\u8fd8\u5728\u6267\u884c\u7684\u8bdd\uff0cBuffer Pool\u5219\u8fd8\u5728\u6d3b\u52a8\uff0cDirty Page\u4e5f\u53ef\u80fd\u8fd8\u4f1a\u4e0d\u65ad\u7684\u589e\u591a\u3002<\/p>\n<p>\u4e00\u822c\uff0c\u5982\u679c\u6ce8\u610f\u5230\u4e86\u4e0a\u9762\u4e09\u70b9\uff1a<\/p>\n<div class=\"myt2\">set global innodb_max_dirty_pages_pct=0<\/div>\n<div class=\"myt2\">set global read_only=1<\/div>\n<div class=\"myt2\">stop slave<\/div>\n<p>\u5173\u95ed\u6570\u636e\u5e93\uff0c\u5c31\u4f1a\u5f88\u5feb\u4e86\u3002\u5982\u679c\u4f60\u628a\u4e0a\u9762\u4e09\u6b65\u505a\u5b8c\uff0c\u7136\u540e\u89c2\u5bdfDirty Page\u7684\u6570\u91cf\uff0c\u5f53\u6570\u91cf\u5f88\u5c11\u65f6\uff0c\u518d\u6267\u884c\u547d\u4ee4\u5173\u5e93\uff0c\u8fd9\u6837\u603b\u80fd\u4fdd\u8bc1\u4ee5\u8f83\u5feb\u7684\u901f\u5ea6\u5b8c\u6210\u5173\u5e93\u547d\u4ee4\u3002<\/p>\n<div class=\"myt1\">4. \u4e00\u4e2a\u6ce8\u610f\u4e8b\u9879<\/div>\n<p>\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4f60\u4e0d\u9700\u7b49\u5230Dirty Page\u7684\u6570\u91cf\u5230\u96f6\uff0c\u624d\u5f00\u59cb\u5173\u95edMySQL\u3002\u56e0\u4e3a\u6709\u65f6\u5019\uff0c\u5373\u4f7f\u5df2\u7ecf\u6ca1\u6709\u6d3b\u52a8\u7684\u4f1a\u8bdd\u65f6\uff0cInnoDB\u7684Insert Buffer\u7684\u5408\u5e76\u4ecd\u7136\u4f1a\u4ea7\u751f\u4e00\u4e9bDirty Page\uff0c\u6240\u4ee5\u8fd9\u65f6\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\uff0c\u7b49\u4e86\u5f88\u4e45\u5f88\u4e45\u5f88\u4e45Dirty Page\u7684\u6570\u91cf\u4ecd\u7136\u5927\u4e8e\u96f6\u3002<\/p>\n<p>\u5176\u5b9e\u8fd9\u65f6\uff0c\u4f60\u5df2\u7ecf\u53ef\u4ee5\u5feb\u901f\u7684\u5173\u95ed\u6570\u636e\u5e93\u4e86\u3002\u6211\u600e\u4e48\u5224\u65ad\u8fd9\u79cd\u60c5\u51b5\u5462\uff1f\u8fd9\u65f6\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7InnoDB\u7684LSN\u6765\u5224\u65ad\uff0c\u4e0b\u9762\u662fSHOW InnoDB Status\u91cc\u9762\u83b7\u53d6\u7684\u4fe1\u606f\uff1a<\/p>\n<pre><div class=\"mycode\">Log sequence number 814 3121743145\r\nLog flushed up to   814 3121092043\r\nLast checkpoint at  814 2826361389\r\n<\/div><\/pre>\n<p>\u8fd9\u91cc\u770b\u5230\uff0c\u5f53\u524d\u7684LSN\u662f814 3121743145\uff0c\u6700\u540e\u4e00\u4e2a\u68c0\u67e5\u70b9\u5728814 2826361389\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e24\u8005\u76f8\u5dee\u4e863121743145-2826361389=295381756\uff0c\u90a3\u4e48\u610f\u5473\u7740InnoDB\u8fd8\u6709\u5f88\u591aDirty Page\u9700\u8981Flush\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u53e6\u4e00\u4e2a\u5e93\u7684LSN\u4fe1\u606f\uff1a<\/p>\n<pre><div class=\"mycode\">Log sequence number 0 1519256161\r\nLog flushed up to   0 1519256161\r\nLast checkpoint at  0 1519256161<\/div><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u8fd9\u91cc\u7684Dirty Page\u90fd\u5df2\u7ecfFlush\u4e86\uff0c\u90a3\u4e48\u5173\u95edInnoDB\u4e5f\u5c31\u5f88\u5feb\u4e86\u3002<\/p>\n<p>\u4e00\u822c\uff0c\u5e76\u4e0d\u9700\u8981\u7b49\u5230\u6700\u540e\u68c0\u67e5\u70b9\u548c\u5f53\u524dLSN\u76f8\u7b49\u624d\u5173\u95ed\uff0c\u4e24\u8005\u53ea\u8981\u76f8\u5dee\u4e0d\u591a\uff08<1000\uff09\u5173\u95ed\u8d77\u6765\u5c31\u5f88\u5feb\u4e86\u3002\n\n\n\n<div class=\"myt1\">5. \u6700\u540e\u518d\u7f57\u55e6\u4e00\u4e0b<\/div>\n<p>\u6211\u8fd9\u4e2a\u4eba\u5199\u535a\u5ba2\u5f88\u7f57\u55e6\u7684\uff0c\u5404\u4f4d\u770b\u5b98\u5728\u5fcd\u8010\u4e00\u4e0b\u5427\u3002<\/p>\n<p>\u5176\u5b9e\uff0c\u50cf\u4e0a\u9762\u8fd9\u6837\u6298\u817e\uff0c\u6574\u4e2a\u5173\u5e93\u7684\u8fc7\u7a0b\u6709\u53ef\u80fd\u5e76\u4e0d\u6bd4\u4f60\u76f4\u63a5\u6267\u884cmysqladmin -uroot shutdown\u5feb\uff0c\u4f46\u662f\u6267\u884c\u4e0a\u9762\u7684\u6b65\u9aa4\uff0c\u4f1a\u8ba9\u4f60\u6e05\u695a\u5173\u5e93\u5230\u5e95\u4e0e\u591a\u4e45\uff0c\u53ef\u4ee5\u8ba9\u4f60\u7684\u5173\u5e93\u547d\u4ee4\u80fd\u591f\u5728\u4e00\u4e2a\u53ef\u4ee5\u9884\u671f\u7684\u65f6\u95f4\u5185\u5b8c\u6210\u3002\u7b80\u5355\u7684\u8bf4\uff0c\u4f1a\u8ba9\u5173\u5e93\u7684\u65f6\u95f4\u5fc3\u91cc\u6709\u4e2a\u5e95\u3002<\/p>\n<p>\u5f53\u4f60\u5e0c\u671b\u4e00\u5207\u90fd\u5fc3\u91cc\u6709\u5e95\u7684\u65f6\u5019\uff0c\u90a3\u4f60\u5c31\u9700\u8981\u6ce8\u610f\u4e0a\u9762\u63d0\u5230\u7684\u4e00\u4e9b\u7ec6\u8282\u3002<\/p>\n<div class=\"myt1\">\u53c2\u8003\u6587\u6863<\/div>\n<p>1. <a href=\"http:\/\/www.mysqlperformanceblog.com\/2009\/04\/15\/how-to-decrease-innodb-shutdown-times\/\">How to decrease InnoDB shutdown times<\/a><\/p>\n<p>2. <a href=\"http:\/\/dbahacker.com\/mysql\/innodb-fast-shutdown\">\u6d4b\u8bd5\u5feb\u901f\u5173\u95edinnodb\u7684\u65b9\u6cd5<\/a><\/p>\n<p>3. MySQL\/InnoDB Manual<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u7528\u7684\u5f15\u64ce\u662fInnoDB\uff0c\u6bcf\u6b21\u6572\u4e0bmysqladmin -uroot -p shutdown\u5173\u95ed\u6570\u636e\u5e93\u7684\u65f6\u5019\uff0c\u603b\u662f\u5f88\u96be\u9884\u6d4b\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u6267\u884c\u591a\u4e45\uff0c\u5b9e\u9645\u7ecf\u9a8c\u8868\u660e\uff0c\u77ed\u5219\u4e94\u79d2\uff0c\u957f\u5219\u4e09\u5341\u5206\u949f\u4e00\u5c0f\u65f6\u90fd\u6709\u53ef\u80fd\u3002\u4e5f\u5206\u4eab\u4e00\u4e0b\u6211\u7684\u7ecf\u9a8c\u5427\u3002 1. \u4e3a\u4ec0\u4e48InnoDB\u5173\u95ed\u4f1a\u6162\uff1f \u4e8b\u5b9e\u4e0a\uff0c\u5e76\u4e0d\u662f\u6bcf\u6b21\u5173\u95edInnoDB\u90fd\u5f88\u6162\u7684\u3002Why\uff1fInnoDB\u8f83\u4e4bMyISAM\uff0c\u4e00\u4e2a\u91cd\u8981\u7279\u6027\u662fInnoDB\u4f1a\u5728\u5185\u5b58\u4e2d\u5f00\u8f9f\u4e00\u4e2aBuffer Pool\u6765\u5b58\u50a8\u6700\u8fd1\u8bbf\u95ee\u7684\u6570\u636e\u5757\/\u7d22\u5f15\u5757\uff0c\u4f7f\u5f97\u4e0b\u6b21\u518d\u6b21\u8bbf\u95ee\u8fd9\u4e2a\u5757\u65f6\u901f\u5ea6\u80fd\u591f\u5f88\u5feb\u3002\u5f53InnoDB\u5bf9\u9700\u8981\u4fee\u6539\u6570\u636e\u5757\u7684\u65f6\u5019\uff0c\u4f1a\u5148\u8bb0\u5f55\u4fee\u6539\u65e5\u5fd7\uff0c\u7136\u540e\u76f4\u63a5\u5bf9Buffer_Pool\u4e2d\u7684\u6570\u636e\u5757\u7684\u64cd\u4f5c\u3002\u8bb0\u5f55\u65e5\u5fd7\u662f\u987a\u5e8f\u5199\uff0c\u5bf9\u6570\u636e\u5757\u7684\u64cd\u4f5c\u662f\u5185\u5b58\u64cd\u4f5c\uff0c\u8fd9\u8ba9InnoDB\u5728\u5f88\u591a\u573a\u666f\u4e0b\u6709\u8fd9\u5f88\u597d\u7684\u901f\u5ea6\u4f18\u52bf\u3002<\/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,4],"tags":[120],"class_list":["post-2166","post","type-post","status-publish","format-standard","hentry","category-mysql","category-code-detail","tag-innodb"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2166","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=2166"}],"version-history":[{"count":16,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2166\/revisions"}],"predecessor-version":[{"id":2710,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/2166\/revisions\/2710"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=2166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=2166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=2166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}