{"id":4244,"date":"2019-05-15T13:20:09","date_gmt":"2019-05-15T05:20:09","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=4244"},"modified":"2019-05-15T13:20:09","modified_gmt":"2019-05-15T05:20:09","slug":"%e8%bf%99%e4%ba%9b-mysql-%e9%9d%a2%e8%af%95%e9%a2%98%e4%bd%a0%e4%bc%9a%e5%a4%9a%e5%b0%91%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4244","title":{"rendered":"\u8fd9\u4e9b MySQL \u9762\u8bd5\u9898\u4f60\u4f1a\u591a\u5c11\uff1f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u66fe\u7ecf\u6211\u4ee5\u4e3a\u4f1a\u4e86\u589e\u5220\u6539\u67e5\uff0c\u4f1a\u4e86 DML\uff0cDDL \u5c31\u662f\u4f1a\u4e86 MySQL\u3002\u76f4\u5230\u73b0\u5728\u6211\u624d\u77e5\u9053\uff0c\u53ea\u4f1a select\u3001update\u3001insert\u3001delete \u53ea\u662f\u5b66 MySQL \u7684\u4e00\u4e2a\u5f00\u59cb\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ea\u4f1a\u8fd9\u4e9b\u4f60\u5728\u9762\u8bd5\u4e2d\u6839\u672c\u90fd\u62ff\u4e0d\u51fa\u624b\uff01\u4eca\u5929\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\uff0c\u4e0b\u9762\u8fd9\u4e9b MySQL \u9762\u8bd5\u9898\uff0c\u4f60\u4f1a\u591a\u5c11\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001MySQL \u4e2d\u5168\u5c40\u9501 FTWRL \u7684\u4f5c\u7528\u548c\u526f\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL \u7684\u5168\u5c40\u9501\u52a0\u9501\u547d\u4ee4\u662f Flush tables with read lock (FTWRL)\u3002\u5f53\u4f60\u9700\u8981\u8ba9\u6574\u4e2a\u5e93\u5904\u4e8e\u53ea\u8bfb\u72b6\u6001\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u547d\u4ee4\u3002\u4f46\u662f\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u9020\u6210\u4ee5\u4e0b\u8bed\u53e5\u4f1a\u88ab\u963b\u585e\uff08\u526f\u4f5c\u7528\uff09\uff1a\u6570\u636e\u66f4\u65b0\u8bed\u53e5\uff08\u6570\u636e\u7684\u589e\u5220\u6539\uff09\u3001\u6570\u636e\u5b9a\u4e49\u8bed\u53e5\uff08\u5305\u62ec\u5efa\u8868\u3001\u4fee\u6539\u8868\u7ed3\u6784\u7b49\uff09\u548c\u66f4\u65b0\u7c7b\u4e8b\u52a1\u7684\u63d0\u4ea4\u8bed\u53e5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001MySQL \u7684 InnoDB \u4e2d\u83b7\u5f97\u4e00\u4e2a\u4e00\u81f4\u6027\u89c6\u56fe\u7684\u65b9\u6cd5\u6709\u591a\u5c11\u79cd\uff1f\u5206\u522b\u662f\u4ec0\u4e48\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u591a\u79cd\u65b9\u6cd5\u3002\u7b2c\u4e00\u79cd\u662f\u52a0\u5168\u5c40\u9501\uff1bFlush tables with read lock (FTWRL)\u3002\u7b2c\u4e8c\u79cd\u662f\u5728\u53ef\u91cd\u590d\u8bfb\u9694\u79bb\u7ea7\u522b\u4e0b\u5f00\u542f\u4e00\u4e2a\u4e8b\u52a1\u3002\u7b2c\u4e09\u79cd\u5c31\u662f\u5b98\u65b9\u81ea\u5e26\u7684\u903b\u8f91\u5907\u4efd\u5de5\u5177\u662f mysqldump\uff1b\u5f53 mysqldump \u4f7f\u7528\u53c2\u6570 \u2013single-transaction \u7684\u65f6\u5019\uff0c\u5bfc\u6570\u636e\u4e4b\u524d\u5c31\u4f1a\u542f\u52a8\u4e00\u4e2a\u4e8b\u52a1\uff0c\u6765\u786e\u4fdd\u62ff\u5230\u4e00\u81f4\u6027\u89c6\u56fe\u3002\u7b2c\u56db\u79cd\u662f\u4f7f\u7528 set global readonly=true \u7684\u65b9\u5f0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001FTWRL \u548c lock tables \u2026 read\/write \u7684\u76f8\u540c\u70b9\u662f\u4ec0\u4e48\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lock tables \u2026 read\/write \u4e0e FTWRL \u7c7b\u4f3c\uff0c\u53ef\u4ee5\u7528 unlock tables \u4e3b\u52a8\u91ca\u653e\u9501\uff0c\u4e5f\u53ef\u4ee5\u5728\u5ba2\u6237\u7aef\u65ad\u5f00\u7684\u65f6\u5019\u81ea\u52a8\u91ca\u653e\u3002\u9700\u8981\u6ce8\u610f\uff0clock tables \u8bed\u6cd5\u9664\u4e86\u4f1a\u9650\u5236\u522b\u7684\u7ebf\u7a0b\u7684\u8bfb\u5199\u5916\uff0c\u4e5f\u9650\u5b9a\u4e86\u672c\u7ebf\u7a0b\u63a5\u4e0b\u6765\u7684\u64cd\u4f5c\u5bf9\u8c61\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u5bf9\u4e8e InnoDB \u5f15\u64ce\u7684\u6570\u636e\u5e93\uff0c\u903b\u8f91\u5907\u4efd\u4e00\u822c\u91c7\u7528\u54ea\u79cd\u65b9\u5f0f\uff1f\u4e3a\u4ec0\u4e48\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u903b\u8f91\u5907\u4efd\u4e00\u822c\u4f1a\u91c7\u7528\u5168\u5c40\u9501\uff0c\u9650\u5236\u6574\u5e93\u4e3a\u53ea\u8bfb\u3002\u5bf9\u4e8e\u5168\u90e8\u662f InnoDB \u5f15\u64ce\u7684\u5e93\uff0c\u5efa\u8bae\u4f60\u9009\u62e9\u4f7f\u7528 \u2013single-transaction \u53c2\u6570\uff0c\u5bf9\u5e94\u7528\u4f1a\u66f4\u53cb\u597d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u4e3a set global readonly=true \u7684\u65b9\u5f0f\u6709\u65f6\u5019\u4f1a\u88ab\u7528\u4f5c\u5176\u4ed6\u903b\u8f91\uff0c\u6bd4\u5982\u7528\u6765\u5224\u65ad\u4e00\u4e2a\u5e93\u662f\u4e3b\u5e93\u8fd8\u662f\u5907\u5e93\u3002\u53e6\u5916\u6574\u4e2a\u5e93\u8bbe\u7f6e\u4e3a readonly \u4e4b\u540e\uff0c\u5982\u679c\u5ba2\u6237\u7aef\u53d1\u751f\u5f02\u5e38\uff0c\u5219\u6570\u636e\u5e93\u5c31\u4f1a\u4e00\u76f4\u4fdd\u6301 readonly \u72b6\u6001\uff0c\u8fd9\u6837\u4f1a\u5bfc\u81f4\u6574\u4e2a\u5e93\u957f\u65f6\u95f4\u5904\u4e8e\u4e0d\u53ef\u5199\u72b6\u6001\uff0c\u98ce\u9669\u8f83\u9ad8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u800c FTWRL \u5728\u6267\u884c\u524d\u6709\u8bfb\u5199\u7684\u8bdd\uff0cFTWRL \u90fd\u4f1a\u7b49\u5f85\uff0c\u76f4\u5230\u8bfb\u5199\u6267\u884c\u5b8c\u6bd5\u540e\u624d\u4f1a\u6267\u884c\u3002FTWRL \u6267\u884c\u7684\u65f6\u5019\u8981\u5237\u810f\u9875\u7684\u6570\u636e\u5230\u78c1\u76d8\uff0c\u56e0\u4e3a\u8981\u4fdd\u6301\u6570\u636e\u7684\u4e00\u81f4\u6027\u3002FTWRL \u66f4\u9002\u5408\u4e0d\u652f\u6301\u4e8b\u52a1\u7684\u5b58\u50a8\u5f15\u64ce\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u800c InnoDB \u662f\u652f\u6301\u4e8b\u52a1\u7684\u3002\u5f53\u4f7f\u7528 mysqldump \u5e76\u4e14\u5e26\u4e0a\u53c2\u6570 \u2013single-transaction \u7684\u65f6\u5019\uff0c\u5bfc\u6570\u636e\u4e4b\u524d\u5c31\u4f1a\u542f\u52a8\u4e00\u4e2a\u4e8b\u52a1\uff0c\u6765\u786e\u4fdd\u62ff\u5230\u4e00\u81f4\u6027\u89c6\u56fe\u3002\u800c\u7531\u4e8e MVCC \u7684\u652f\u6301\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\u6570\u636e\u662f\u53ef\u4ee5\u6b63\u5e38\u66f4\u65b0\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5\u3001\u5168\u5e93\u53ea\u8bfb\uff0c\u4e3a\u4ec0\u4e48\u4e0d\u4f7f\u7528 set global readonly=true \u7684\u65b9\u5f0f\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u95ee\u9898\uff0c\u4e0a\u9762\u7b2c\u56db\u9898\u5df2\u6709\u89e3\u7b54\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">set global readonly=true \u786e\u5b9e\u53ef\u4ee5\u8ba9\u5168\u5e93\u8fdb\u5165\u53ea\u8bfb\u72b6\u6001\uff0c\u4f46\u8fd8\u662f\u4e0d\u5efa\u8bae\u4f60\u4f7f\u7528\uff0c\u4e3b\u8981\u6709\u4e24\u4e2a\u539f\u56e0\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u662f\uff0c\u5728\u6709\u4e9b\u7cfb\u7edf\u4e2d\uff0creadonly \u7684\u503c\u4f1a\u88ab\u7528\u6765\u505a\u5176\u4ed6\u903b\u8f91\uff0c\u6bd4\u5982\u7528\u6765\u5224\u65ad\u4e00\u4e2a\u5e93\u662f\u4e3b\u5e93\u8fd8\u662f\u5907\u5e93\u3002\u56e0\u6b64\uff0c\u4fee\u6539 global \u53d8\u91cf\u7684\u65b9\u5f0f\u5f71\u54cd\u9762\u66f4\u5927\uff0c\u56e0\u6b64\u4e0d\u5efa\u8bae\u4f60\u4f7f\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e8c\u662f\uff0c\u5728\u5f02\u5e38\u5904\u7406\u673a\u5236\u4e0a\u6709\u5dee\u5f02\u3002\u5c06\u6574\u4e2a\u5e93\u8bbe\u7f6e\u4e3a readonly \u4e4b\u540e\uff0c\u5982\u679c\u5ba2\u6237\u7aef\u53d1\u751f\u5f02\u5e38\uff0c\u5219\u6570\u636e\u5e93\u5c31\u4f1a\u4e00\u76f4\u4fdd\u6301 readonly \u72b6\u6001\uff0c\u8fd9\u6837\u4f1a\u5bfc\u81f4\u6574\u4e2a\u5e93\u957f\u65f6\u95f4\u5904\u4e8e\u4e0d\u53ef\u5199\u72b6\u6001\uff0c\u98ce\u9669\u8f83\u9ad8\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g31xi9dtq0j20u01hc44v.jpg\" alt=\"\" \/><figcaption>\u901a\u8fc7\u6211\u6d77\u62a5\u4e0a\u7684\u4e8c\u7ef4\u7801\u626b\u63cf\u8d2d\u4e70\u540e\u52a0xttblog\u5fae\u4fe1\uff0c\u8fd4\u73b024<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u66f4\u591a\u5173\u4e8e MySQL \u7684\u9ad8\u7ea7\u9762\u8bd5\u9898\u8bf7\u6253\u5f00\u4e0b\u9762\u7684\u5c0f\u7a0b\u5e8f\u8fdb\u884c\u9605\u8bfb\u3002\u6216\u8005\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u8d2d\u4e70\u6781\u5ba2\u65f6\u95f4\u7684\u300aMySQL\u5b9e\u621845\u8bb2\u300b\u8fdb\u884c\u5b66\u4e60\u3002\u626b\u63cf\u4e0b\u65b9\u6d77\u62a5\u4e0a\u7684\u4e8c\u7ef4\u7801\uff0c\u8d2d\u4e70\u540e\u52a0\u6211\u5fae\u4fe1\u53f7\uff1axttblog\uff0c\u5907\u6ce8\u201c\u8fd4\u73b0\u201d\u3002\u6211\u8fd4\u4f60\u5fae\u4fe1 24 \u5143\u7ea2\u5305\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4244\">\u8fd9\u4e9b MySQL \u9762\u8bd5\u9898\u4f60\u4f1a\u591a\u5c11\uff1f<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u66fe\u7ecf\u6211\u4ee5\u4e3a\u4f1a\u4e86\u589e\u5220\u6539\u67e5\uff0c\u4f1a\u4e86 DML\uff0cDDL \u5c31\u662f\u4f1a\u4e86 MySQL\u3002\u76f4\u5230\u73b0\u5728\u6211\u624d\u77e5\u9053\uff0c\u53ea\u4f1a select\u3001up [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[83,472,546,579,410],"class_list":["post-4244","post","type-post","status-publish","format-standard","hentry","category-sql","tag-mysql","tag-rest","tag-546","tag-579","tag-410"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4244"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4244\/revisions"}],"predecessor-version":[{"id":4245,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4244\/revisions\/4245"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}