{"id":3629,"date":"2019-07-12T17:02:12","date_gmt":"2019-07-12T09:02:12","guid":{"rendered":"https:\/\/damogame.cn\/wordpress\/?p=3629"},"modified":"2019-07-12T17:02:12","modified_gmt":"2019-07-12T09:02:12","slug":"mysql%e5%8f%82%e6%95%b0%ef%bc%9ainnodb_flush_log_at_trx_commit-%e5%92%8c-sync_binlog","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/3629","title":{"rendered":"MySQL\u53c2\u6570\uff1ainnodb_flush_log_at_trx_commit \u548c sync_binlog"},"content":{"rendered":"<div class=\"entry-content\">\n<p><code>innodb_flush_log_at_trx_commit<\/code>\u00a0\u548c\u00a0<code>sync_binlog<\/code>\u00a0\u662f MySQL \u7684\u4e24\u4e2a\u914d\u7f6e\u53c2\u6570\uff0c\u524d\u8005\u662f InnoDB \u5f15\u64ce\u7279\u6709\u7684\u3002\u4e4b\u6240\u4ee5\u628a\u8fd9\u4e24\u4e2a\u53c2\u6570\u653e\u5728\u4e00\u8d77\u8ba8\u8bba\uff0c\u662f\u56e0\u4e3a\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5b83\u4eec\u7684\u914d\u7f6e\u5bf9\u4e8e MySQL \u7684\u6027\u80fd\u6709\u5f88\u5927\u5f71\u54cd\u3002<\/p>\n<h2 id=\"1-innodb-flush-log-at-trx-commit\">1. innodb_flush_log_at_trx_commit<\/h2>\n<p>\u7b80\u800c\u8a00\u4e4b\uff0c<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/4.1\/en\/innodb-parameters.html#sysvar_innodb_flush_log_at_trx_commit\"><code>innodb_flush_log_at_trx_commit<\/code><\/a>\u00a0\u53c2\u6570\u6307\u5b9a\u4e86 InnoDB \u5728\u4e8b\u52a1\u63d0\u4ea4\u540e\u7684\u65e5\u5fd7\u5199\u5165\u9891\u7387\u3002\u8fd9\u4e48\u8bf4\u5176\u5b9e\u5e76\u4e0d\u4e25\u8c28\uff0c\u4e14\u770b\u5176\u4e0d\u540c\u53d6\u503c\u7684\u610f\u4e49\u548c\u8868\u73b0\u3002<\/p>\n<ol>\n<li>\u5f53\u00a0<code>innodb_flush_log_at_trx_commit<\/code>\u00a0\u53d6\u503c\u4e3a\u00a0<code>0<\/code>\u00a0\u7684\u65f6\u5019\uff0clog buffer \u4f1a \u6bcf\u79d2\u5199\u5165\u5230\u65e5\u5fd7\u6587\u4ef6\u5e76\u5237\u5199\uff08flush\uff09\u5230\u78c1\u76d8\u3002\u4f46\u6bcf\u6b21\u4e8b\u52a1\u63d0\u4ea4\u4e0d\u4f1a\u6709\u4efb\u4f55\u5f71\u54cd\uff0c\u4e5f\u5c31\u662f log buffer \u7684\u5237\u5199\u64cd\u4f5c\u548c\u4e8b\u52a1\u63d0\u4ea4\u64cd\u4f5c\u6ca1\u6709\u5173\u7cfb\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0cMySQL\u6027\u80fd\u6700\u597d\uff0c\u4f46\u5982\u679c mysqld \u8fdb\u7a0b\u5d29\u6e83\uff0c\u901a\u5e38\u4f1a\u5bfc\u81f4\u6700\u540e 1s \u7684\u65e5\u5fd7\u4e22\u5931\u3002<\/li>\n<li>\u5f53\u53d6\u503c\u4e3a\u00a0<code>1<\/code>\u00a0\u65f6\uff0c\u6bcf\u6b21\u4e8b\u52a1\u63d0\u4ea4\u65f6\uff0clog buffer \u4f1a\u88ab\u5199\u5165\u5230\u65e5\u5fd7\u6587\u4ef6\u5e76\u5237\u5199\u5230\u78c1\u76d8\u3002\u8fd9\u4e5f\u662f\u9ed8\u8ba4\u503c\u3002\u8fd9\u662f\u6700\u5b89\u5168\u7684\u914d\u7f6e\uff0c\u4f46\u7531\u4e8e\u6bcf\u6b21\u4e8b\u52a1\u90fd\u9700\u8981\u8fdb\u884c\u78c1\u76d8I\/O\uff0c\u6240\u4ee5\u4e5f\u6700\u6162\u3002<\/li>\n<li>\u5f53\u53d6\u503c\u4e3a\u00a0<code>2<\/code>\u00a0\u65f6\uff0c\u6bcf\u6b21\u4e8b\u52a1\u63d0\u4ea4\u4f1a\u5199\u5165\u65e5\u5fd7\u6587\u4ef6\uff0c\u4f46\u5e76\u4e0d\u4f1a\u7acb\u5373\u5237\u5199\u5230\u78c1\u76d8\uff0c\u65e5\u5fd7\u6587\u4ef6\u4f1a\u6bcf\u79d2\u5237\u5199\u4e00\u6b21\u5230\u78c1\u76d8\u3002\u8fd9\u65f6\u5982\u679c mysqld \u8fdb\u7a0b\u5d29\u6e83\uff0c\u7531\u4e8e\u65e5\u5fd7\u5df2\u7ecf\u5199\u5165\u5230\u7cfb\u7edf\u7f13\u5b58\uff0c\u6240\u4ee5\u5e76\u4e0d\u4f1a\u4e22\u5931\u6570\u636e\uff1b\u5728\u64cd\u4f5c\u7cfb\u7edf\u5d29\u6e83\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u5e38\u4f1a\u5bfc\u81f4\u6700\u540e 1s \u7684\u65e5\u5fd7\u4e22\u5931\u3002<\/li>\n<\/ol>\n<p>\u4e0a\u9762\u8bf4\u5230\u7684\u300c\u6700\u540e 1s\u300d\u5e76\u4e0d\u662f\u7edd\u5bf9\u7684\uff0c\u6709\u7684\u65f6\u5019\u4f1a\u4e22\u5931\u66f4\u591a\u6570\u636e\u3002\u6709\u65f6\u5019\u7531\u4e8e\u8c03\u5ea6\u7684\u95ee\u9898\uff0c\u6bcf\u79d2\u5237\u5199\uff08once-per-second flushing\uff09\u5e76\u4e0d\u80fd\u4fdd\u8bc1 100% \u6267\u884c\u3002\u5bf9\u4e8e\u4e00\u4e9b\u6570\u636e\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u8981\u6c42\u4e0d\u9ad8\u7684\u5e94\u7528\uff0c\u914d\u7f6e\u4e3a\u00a0<code>2<\/code>\u00a0\u5c31\u8db3\u591f\u4e86\uff1b\u5982\u679c\u4e3a\u4e86\u6700\u9ad8\u6027\u80fd\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u00a0<code>0<\/code>\u3002\u6709\u4e9b\u5e94\u7528\uff0c\u5982\u652f\u4ed8\u670d\u52a1\uff0c\u5bf9\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u8981\u6c42\u5f88\u9ad8\uff0c\u6240\u4ee5\u5373\u4f7f\u6700\u6162\uff0c\u4e5f\u6700\u597d\u8bbe\u7f6e\u4e3a\u00a0<code>1<\/code>.<\/p>\n<h2 id=\"2-sync-binlog\">2. sync_binlog<\/h2>\n<p><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.5\/en\/replication-options-binary-log.html#sysvar_sync_binlog\">sync_binlog<\/a>\u00a0\u662f MySQL \u7684\u4e8c\u8fdb\u5236\u65e5\u5fd7\uff08binary log\uff09\u540c\u6b65\u5230\u78c1\u76d8\u7684\u9891\u7387\u3002MySQL server \u5728 binary log \u6bcf\u5199\u5165\u00a0<code>sync_binlog<\/code>\u00a0\u6b21\u540e\uff0c\u5237\u5199\u5230\u78c1\u76d8\u3002<\/p>\n<p>\u5982\u679c\u00a0<code>autocommit<\/code>\u00a0\u5f00\u542f\uff0c\u6bcf\u4e2a\u8bed\u53e5\u90fd\u5199\u4e00\u6b21 binary log\uff0c\u5426\u5219\u6bcf\u6b21\u4e8b\u52a1\u5199\u4e00\u6b21\u3002\u9ed8\u8ba4\u503c\u662f\u00a0<code>0<\/code>\uff0c\u4e0d\u4e3b\u52a8\u540c\u6b65\uff0c\u800c\u4f9d\u8d56\u64cd\u4f5c\u7cfb\u7edf\u672c\u8eab\u4e0d\u5b9a\u671f\u628a\u6587\u4ef6\u5185\u5bb9 flush \u5230\u78c1\u76d8\u3002\u8bbe\u4e3a\u00a0<code>1<\/code>\u00a0\u6700\u5b89\u5168\uff0c\u5728\u6bcf\u4e2a\u8bed\u53e5\u6216\u4e8b\u52a1\u540e\u540c\u6b65\u4e00\u6b21 binary log\uff0c\u5373\u4f7f\u5728\u5d29\u6e83\u65f6\u4e5f\u6700\u591a\u4e22\u5931\u4e00\u4e2a\u8bed\u53e5\u6216\u4e8b\u52a1\u7684\u65e5\u5fd7\uff0c\u4f46\u56e0\u6b64\u4e5f\u6700\u6162\u3002<\/p>\n<p>\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u5bf9\u6570\u636e\u7684\u4e00\u81f4\u6027\u5e76\u6ca1\u6709\u5f88\u4e25\u683c\u7684\u8981\u6c42\uff0c\u6240\u4ee5\u5e76\u4e0d\u4f1a\u628a\u00a0<code>sync_binlog<\/code>\u00a0\u914d\u7f6e\u6210\u00a0<code>1<\/code>. \u4e3a\u4e86\u8ffd\u6c42\u9ad8\u5e76\u53d1\uff0c\u63d0\u5347\u6027\u80fd\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u00a0<code>100<\/code>\u00a0\u6216\u76f4\u63a5\u7528\u00a0<code>0<\/code>. \u800c\u548c\u00a0<code>innodb_flush_log_at_trx_commit<\/code>\u00a0\u4e00\u6837\uff0c\u5bf9\u4e8e\u652f\u4ed8\u670d\u52a1\u8fd9\u6837\u7684\u5e94\u7528\uff0c\u8fd8\u662f\u6bd4\u8f83\u63a8\u8350\u00a0<code>sync_binlog = 1<\/code>.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>innodb_flush_log_at_<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[118],"class_list":["post-3629","post","type-post","status-publish","format-standard","hentry","tag-02-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/3629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=3629"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/3629\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=3629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=3629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=3629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}