{"id":5429,"date":"2024-11-14T08:23:43","date_gmt":"2024-11-14T00:23:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5429\/"},"modified":"2024-11-14T08:23:43","modified_gmt":"2024-11-14T00:23:43","slug":"mysql%e9%94%81%e6%80%8e%e4%b9%88%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5429\/","title":{"rendered":"mysql\u9501\u600e\u4e48\u5b9e\u73b0"},"content":{"rendered":"<blockquote><p>\n  mysql \u7684\u9501\u5b9a\u673a\u5236\u91c7\u7528\u4e50\u89c2\u5e76\u53d1\u63a7\u5236\uff0c\u4f7f\u7528\u8868\u9501\u3001\u884c\u9501\u548c\u95f4\u9699\u9501\u3002\u9501\u901a\u8fc7\u8bfb\u5199\u9501\u5b9e\u73b0\uff0c\u5e76\u5728\u4e8b\u52a1\u63d0\u4ea4\u65f6\u9a8c\u8bc1\u3002\u9501\u5b9a\u5347\u7ea7\u5141\u8bb8\u5728\u9700\u8981\u66f4\u5927\u8303\u56f4\u8bbf\u95ee\u65f6\u5347\u7ea7\u9501\u3002\u9501\u5728\u4e8b\u52a1\u63d0\u4ea4\u6216\u56de\u6eda\u65f6\u91ca\u653e\uff0c\u6216\u901a\u8fc7 unlock tables \u8bed\u53e5\u624b\u52a8\u91ca\u653e\u3002\u9501\u7684\u4f7f\u7528\u5e94\u8c28\u614e\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5f71\u54cd\u6570\u636e\u5e93\u6027\u80fd\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052812392357868.jpg\" class=\"aligncenter\" title=\"mysql\u9501\u600e\u4e48\u5b9e\u73b0\u63d2\u56fe\" alt=\"mysql\u9501\u600e\u4e48\u5b9e\u73b0\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u9501\u5b9a\u673a\u5236<\/strong><\/p>\n<p><strong>MySQL \u4e2d\u9501\u7684\u7c7b\u578b<\/strong><\/p>\n<ul>\n<li> <strong>\u8868\u9501 (Table Locks)<\/strong>\uff1a\u9501\u5b9a\u6574\u4e2a\u8868\uff0c\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u8bbf\u95ee\u4efb\u4f55\u6570\u636e\u884c\u3002<\/li>\n<li> <strong>\u884c\u9501 (Row Locks)<\/strong>\uff1a\u9501\u5b9a\u7279\u5b9a\u6570\u636e\u884c\uff0c\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u5bf9\u8be5\u884c\u8fdb\u884c\u3002<\/li>\n<li> <strong>\u95f4\u9699\u9501 (Gap Locks)<\/strong>\uff1a\u5728\u73b0\u6709\u884c\u5468\u56f4\u9501\u5b9a\u6f5c\u5728\u7684\u63d2\u5165\u7a7a\u95f4\uff0c\u9632\u6b62\u5e76\u53d1\u63d2\u5165\u3002<\/li>\n<\/ul>\n<p><strong>MySQL \u9501\u5b9a\u673a\u5236<\/strong><\/p>\n<p>MySQL \u4f7f\u7528\u4e50\u89c2\u5e76\u53d1\u63a7\u5236\uff08OCC\uff09\u673a\u5236\u6765\u7ba1\u7406\u9501\u3002\u8fd9\u610f\u5473\u7740\uff0c\u6570\u636e\u5728\u8bfb\u5199\u64cd\u4f5c\u671f\u95f4\u4e0d\u4f1a\u88ab\u9501\u5b9a\uff0c\u4f46\u4f1a\u5728\u63d0\u4ea4\u4e8b\u52a1\u65f6\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n<p><strong>\u9501\u5b9a\u7684\u5b9e\u73b0<\/strong><\/p>\n<p>MySQL \u4f7f\u7528\u4e24\u79cd\u4e3b\u8981\u673a\u5236\u6765\u5b9e\u73b0\u9501\u5b9a\uff1a<\/p>\n<ul>\n<li> <strong>Read Locks (RL)<\/strong>\uff1a\u5728\u8bfb\u53d6\u6570\u636e\u884c\u65f6\u83b7\u53d6\u3002\u5b83\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u4fee\u6539\u884c\u3002<\/li>\n<li> <strong>Write Locks (WL)<\/strong>\uff1a\u5728\u5199\u5165\u6216\u66f4\u65b0\u6570\u636e\u884c\u65f6\u83b7\u53d6\u3002\u5b83\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u8bfb\u53d6\u6216\u5199\u5165\u884c\u3002<\/li>\n<\/ul>\n<p><strong>\u9501\u5b9a\u7684\u5347\u7ea7<\/strong><\/p>\n<p>\u5f53\u9700\u8981\u5bf9\u4e00\u7ec4\u884c\u6267\u884c\u591a\u4e2a\u64cd\u4f5c\u65f6\uff0cMySQL \u4f1a\u4f7f\u7528\u9501\u5347\u7ea7\u673a\u5236\u3002\u4f8b\u5982\uff0c\u5f53\u5bf9\u591a\u4e2a\u884c\u8fdb\u884c\u66f4\u65b0\u65f6\uff0c\u4ece\u884c\u9501\u5347\u7ea7\u5230\u8868\u9501\u3002<\/p>\n<p><strong>\u9501\u5b9a\u7684\u91ca\u653e<\/strong><\/p>\n<p>\u9501\u5728\u4e8b\u52a1\u63d0\u4ea4\u6216\u56de\u6eda\u65f6\u91ca\u653e\u3002\u8fd8\u53ef\u4ee5\u4f7f\u7528 UNLOCK TABLES \u8bed\u53e5\u624b\u52a8\u91ca\u653e\u9501\u3002<\/p>\n<p><strong>\u5f71\u54cd<\/strong><\/p>\n<p>\u9501\u7684\u4f7f\u7528\u4f1a\u5bf9\u6570\u636e\u5e93\u6027\u80fd\u4ea7\u751f\u91cd\u5927\u5f71\u54cd\u3002\u9891\u7e41\u7684\u9501\u4e89\u7528\u4f1a\u5bfc\u81f4\u7b49\u5f85\u65f6\u95f4\u589e\u52a0\u548c\u541e\u5410\u91cf\u4e0b\u964d\u3002\u56e0\u6b64\uff0c\u5e94\u8c28\u614e\u4f7f\u7528\u9501\uff0c\u5e76\u8003\u8651\u66ff\u4ee3\u89e3\u51b3\u65b9\u6848\uff0c\u4f8b\u5982\u4f7f\u7528\u7d22\u5f15\u6216\u5206\u533a\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u9501\u600e\u4e48\u5b9e\u73b0\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>mysql \u7684\u9501\u5b9a\u673a\u5236\u91c7\u7528\u4e50\u89c2\u5e76\u53d1\u63a7\u5236\uff0c\u4f7f\u7528\u8868\u9501\u3001\u884c\u9501\u548c\u95f4\u9699\u9501\u3002\u9501\u901a\u8fc7\u8bfb\u5199\u9501\u5b9e\u73b0\uff0c\u5e76\u5728\u4e8b\u52a1\u63d0\u4ea4\u65f6\u9a8c\u8bc1\u3002\u9501\u5b9a\u5347\u7ea7\u5141\u8bb8\u5728\u9700\u8981\u66f4\u5927\u8303\u56f4\u8bbf\u95ee\u65f6\u5347\u7ea7\u9501\u3002\u9501\u5728\u4e8b\u52a1\u63d0\u4ea4\u6216\u56de\u6eda\u65f6\u91ca\u653e\uff0c\u6216\u901a\u8fc7 unlock tables \u8bed\u53e5\u624b\u52a8\u91ca\u653e\u3002\u9501\u7684\u4f7f\u7528\u5e94\u8c28\u614e\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5f71\u54cd\u6570\u636e\u5e93\u6027\u80fd\u3002 MySQL \u9501\u5b9a\u673a\u5236 MySQL \u4e2d\u9501\u7684\u7c7b\u578b \u8868\u9501 (Table Locks)\uff1a\u9501\u5b9a\u6574\u4e2a\u8868\uff0c\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u8bbf\u95ee\u4efb\u4f55\u6570\u636e\u884c\u3002 \u884c\u9501 (Row Locks)\uff1a\u9501\u5b9a\u7279\u5b9a\u6570\u636e\u884c\uff0c\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u5bf9\u8be5\u884c\u8fdb\u884c\u3002 \u95f4\u9699\u9501 (Gap Locks)\uff1a\u5728\u73b0\u6709\u884c\u5468\u56f4\u9501\u5b9a\u6f5c\u5728\u7684\u63d2\u5165\u7a7a\u95f4\uff0c\u9632\u6b62\u5e76\u53d1\u63d2\u5165\u3002 MySQL \u9501\u5b9a\u673a\u5236 MySQL \u4f7f\u7528\u4e50\u89c2\u5e76\u53d1\u63a7\u5236\uff08OCC\uff09\u673a\u5236\u6765\u7ba1\u7406\u9501\u3002\u8fd9\u610f\u5473\u7740\uff0c\u6570\u636e\u5728\u8bfb\u5199\u64cd\u4f5c\u671f\u95f4\u4e0d\u4f1a\u88ab\u9501\u5b9a\uff0c\u4f46\u4f1a\u5728\u63d0\u4ea4\u4e8b\u52a1\u65f6\u8fdb\u884c\u9a8c\u8bc1\u3002 \u9501\u5b9a\u7684\u5b9e\u73b0 MySQL \u4f7f\u7528\u4e24\u79cd\u4e3b\u8981\u673a\u5236\u6765\u5b9e\u73b0\u9501\u5b9a\uff1a Read Locks (RL)\uff1a\u5728\u8bfb\u53d6\u6570\u636e\u884c\u65f6\u83b7\u53d6\u3002\u5b83\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u4fee\u6539\u884c\u3002 Write Locks (WL)\uff1a\u5728\u5199\u5165\u6216\u66f4\u65b0\u6570\u636e\u884c\u65f6\u83b7\u53d6\u3002\u5b83\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u8bfb\u53d6\u6216\u5199\u5165\u884c\u3002 \u9501\u5b9a\u7684\u5347\u7ea7 \u5f53\u9700\u8981\u5bf9\u4e00\u7ec4\u884c\u6267\u884c\u591a\u4e2a\u64cd\u4f5c\u65f6\uff0cMySQL \u4f1a\u4f7f\u7528\u9501\u5347\u7ea7\u673a\u5236\u3002\u4f8b\u5982\uff0c\u5f53\u5bf9\u591a\u4e2a\u884c\u8fdb\u884c\u66f4\u65b0\u65f6\uff0c\u4ece\u884c\u9501\u5347\u7ea7\u5230\u8868\u9501\u3002 \u9501\u5b9a\u7684\u91ca\u653e \u9501\u5728\u4e8b\u52a1\u63d0\u4ea4\u6216\u56de\u6eda\u65f6\u91ca\u653e\u3002\u8fd8\u53ef\u4ee5\u4f7f\u7528 UNLOCK TABLES \u8bed\u53e5\u624b\u52a8\u91ca\u653e\u9501\u3002 \u5f71\u54cd \u9501\u7684\u4f7f\u7528\u4f1a\u5bf9\u6570\u636e\u5e93\u6027\u80fd\u4ea7\u751f\u91cd\u5927\u5f71\u54cd\u3002\u9891\u7e41\u7684\u9501\u4e89\u7528\u4f1a\u5bfc\u81f4\u7b49\u5f85\u65f6\u95f4\u589e\u52a0\u548c\u541e\u5410\u91cf\u4e0b\u964d\u3002\u56e0\u6b64\uff0c\u5e94\u8c28\u614e\u4f7f\u7528\u9501\uff0c\u5e76\u8003\u8651\u66ff\u4ee3\u89e3\u51b3\u65b9\u6848\uff0c\u4f8b\u5982\u4f7f\u7528\u7d22\u5f15\u6216\u5206\u533a\u3002 \u4ee5\u4e0a\u5c31\u662f\u9501\u600e\u4e48\u5b9e\u73b0\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5429","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5429"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5429\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}