{"id":5144,"date":"2024-11-14T08:43:00","date_gmt":"2024-11-14T00:43:00","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5144\/"},"modified":"2024-11-14T08:43:00","modified_gmt":"2024-11-14T00:43:00","slug":"mysql%e9%94%81%e8%a1%a8%e6%80%8e%e4%b9%88%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5144\/","title":{"rendered":"mysql\u9501\u8868\u600e\u4e48\u4f7f\u7528"},"content":{"rendered":"<blockquote><p>\n  \u4f7f\u7528 lock tables \u8bed\u53e5\u663e\u5f0f\u9501\u5b9a mysql \u8868\uff0c\u652f\u6301 read\uff08\u5171\u4eab\u9501\uff09\u3001write\uff08\u6392\u4ed6\u9501\uff09\u3001low_priority write\uff08\u6392\u4ed6\u9501\uff0c\u6b7b\u9501\u65f6\u4f18\u5148\u7ea7\u8f83\u4f4e\uff09\u7b49\u9501\u7c7b\u578b\u3002\u9690\u5f0f\u9501\u8868\u5219\u5728\u67d0\u4e9b\u67e5\u8be2\uff08\u5982\u6570\u636e\u4fee\u6539\uff09\u4e0a\u81ea\u52a8\u5e94\u7528\u3002\u9501\u8868\u4f1a\u9650\u5236\u5176\u4ed6\u4f1a\u8bdd\u8bbf\u95ee\u8868\uff0c\u5e94\u8c28\u614e\u4f7f\u7528\uff0c\u5e76\u6ce8\u610f\u91ca\u653e\u9501\uff08unlock tables\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/22\/2024052216422616072.jpg\" class=\"aligncenter\" title=\"mysql\u9501\u8868\u600e\u4e48\u4f7f\u7528\u63d2\u56fe\" alt=\"mysql\u9501\u8868\u600e\u4e48\u4f7f\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 MySQL \u9501\u8868<\/strong><\/p>\n<p><strong>\u5f00\u573a\u767d\uff1a<\/strong><\/p>\n<p>\u8981\u5bf9 MySQL \u6570\u636e\u5e93\u8868\u8fdb\u884c\u9501\u5b9a\uff0c\u53ef\u4ee5\u91c7\u53d6\u591a\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4f7f\u7528 LOCK TABLES \u8bed\u53e5\u6765\u663e\u5f0f\u9501\u5b9a\u8868\u7684\u65b9\u6cd5\u3002<\/p>\n<p><strong>\u4f7f\u7528 LOCK TABLES \u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>LOCK TABLES table_name [AS alias] [lock_type] [, ...]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>table_name\uff1a\u8981\u9501\u5b9a\u7684\u8868\u540d\u3002<\/li>\n<li>alias\uff08\u53ef\u9009\uff09\uff1a\u7528\u4e8e\u8868\u540d\u7684\u522b\u540d\u3002<\/li>\n<li>lock_type\uff1a\u8981\u5e94\u7528\u7684\u9501\u7c7b\u578b\uff08\u4f8b\u5982\uff0cREAD\u3001WRITE\u3001LOW_PRIORITY WRITE\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u9501\u7c7b\u578b\uff1a<\/strong><\/p>\n<p>MySQL \u652f\u6301\u4ee5\u4e0b\u9501\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>READ\uff1a\u5171\u4eab\u9501\uff0c\u5141\u8bb8\u5176\u4ed6\u4f1a\u8bdd\u8bfb\u53d6\u8868\uff0c\u4f46\u4e0d\u80fd\u5199\u5165\u3002<\/li>\n<li>WRITE\uff1a\u6392\u4ed6\u9501\uff0c\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u8bbf\u95ee\u6216\u4fee\u6539\u8868\u3002<\/li>\n<li>LOW_PRIORITY WRITE\uff1a\u6392\u4ed6\u9501\uff0c\u4f46\u5728\u51fa\u73b0\u6b7b\u9501\u65f6\u4f18\u5148\u7ea7\u8f83\u4f4e\u3002<\/li>\n<\/ul>\n<p><strong>\u663e\u5f0f\u4f7f\u7528 LOCK TABLES\uff1a<\/strong><\/p>\n<p>\u8981\u660e\u786e\u9501\u5b9a\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528 LOCK TABLES \u8bed\u53e5\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>LOCK TABLES my_table READ;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u5bf9 my_table \u8868\u5e94\u7528\u5171\u4eab\u9501\uff0c\u5141\u8bb8\u5176\u4ed6\u4f1a\u8bdd\u8bfb\u53d6\u8868\u4f46\u4e0d\u80fd\u5199\u5165\u3002<\/p>\n<p><strong>\u9690\u5f0f\u4f7f\u7528 LOCK TABLES\uff1a<\/strong><\/p>\n<p>MySQL \u8fd8\u53ef\u4ee5\u81ea\u52a8\u5728\u67d0\u4e9b\u67e5\u8be2\u4e0a\u5e94\u7528\u9690\u5f0f\u9501\u8868\u3002\u4f8b\u5982\uff0cDELETE\u3001UPDATE \u548c INSERT \u7b49\u6570\u636e\u4fee\u6539\u8bed\u53e5\u5c06\u5728\u53d7\u5f71\u54cd\u7684\u8868\u4e0a\u81ea\u52a8\u8bbe\u7f6e\u6392\u4ed6\u9501\u3002<\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u9501\u8868\u4f1a\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u8bbf\u95ee\u6216\u4fee\u6539\u8868\uff0c\u56e0\u6b64\u5e94\u8c28\u614e\u4f7f\u7528\u3002<\/li>\n<li>\u5728\u9501\u5b9a\u8868\u4e4b\u524d\uff0c\u5e94\u786e\u5b9a\u9501\u5b9a\u7684\u6301\u7eed\u65f6\u95f4\uff0c\u5e76\u786e\u4fdd\u4e0d\u4f1a\u5bfc\u81f4\u6b7b\u9501\u3002<\/li>\n<li>\u4f7f\u7528 UNLOCK TABLES \u8bed\u53e5\u91ca\u653e\u9501\u3002<\/li>\n<li>\u4e5f\u53ef\u4ee5\u4f7f\u7528 SHOW PROCESSLIST \u8bed\u53e5\u67e5\u770b\u5f53\u524d\u7684\u9501\u8868\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u9501\u8868\u600e\u4e48\u4f7f\u7528\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>\u4f7f\u7528 lock tables \u8bed\u53e5\u663e\u5f0f\u9501\u5b9a mysql \u8868\uff0c\u652f\u6301 read\uff08\u5171\u4eab\u9501\uff09\u3001write\uff08\u6392\u4ed6\u9501\uff09\u3001low_priority write\uff08\u6392\u4ed6\u9501\uff0c\u6b7b\u9501\u65f6\u4f18\u5148\u7ea7\u8f83\u4f4e\uff09\u7b49\u9501\u7c7b\u578b\u3002\u9690\u5f0f\u9501\u8868\u5219\u5728\u67d0\u4e9b\u67e5\u8be2\uff08\u5982\u6570\u636e\u4fee\u6539\uff09\u4e0a\u81ea\u52a8\u5e94\u7528\u3002\u9501\u8868\u4f1a\u9650\u5236\u5176\u4ed6\u4f1a\u8bdd\u8bbf\u95ee\u8868\uff0c\u5e94\u8c28\u614e\u4f7f\u7528\uff0c\u5e76\u6ce8\u610f\u91ca\u653e\u9501\uff08unlock tables\uff09\u3002 \u5982\u4f55\u4f7f\u7528 MySQL \u9501\u8868 \u5f00\u573a\u767d\uff1a \u8981\u5bf9 MySQL \u6570\u636e\u5e93\u8868\u8fdb\u884c\u9501\u5b9a\uff0c\u53ef\u4ee5\u91c7\u53d6\u591a\u79cd\u65b9\u5f0f\u6765\u5b9e\u73b0\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4f7f\u7528 LOCK TABLES \u8bed\u53e5\u6765\u663e\u5f0f\u9501\u5b9a\u8868\u7684\u65b9\u6cd5\u3002 \u4f7f\u7528 LOCK TABLES \u8bed\u6cd5\uff1a LOCK TABLES table_name [AS alias] [lock_type] [, &#8230;] \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a table_name\uff1a\u8981\u9501\u5b9a\u7684\u8868\u540d\u3002 alias\uff08\u53ef\u9009\uff09\uff1a\u7528\u4e8e\u8868\u540d\u7684\u522b\u540d\u3002 lock_type\uff1a\u8981\u5e94\u7528\u7684\u9501\u7c7b\u578b\uff08\u4f8b\u5982\uff0cREAD\u3001WRITE\u3001LOW_PRIORITY WRITE\uff09\u3002 \u9501\u7c7b\u578b\uff1a MySQL \u652f\u6301\u4ee5\u4e0b\u9501\u7c7b\u578b\uff1a READ\uff1a\u5171\u4eab\u9501\uff0c\u5141\u8bb8\u5176\u4ed6\u4f1a\u8bdd\u8bfb\u53d6\u8868\uff0c\u4f46\u4e0d\u80fd\u5199\u5165\u3002 WRITE\uff1a\u6392\u4ed6\u9501\uff0c\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u8bbf\u95ee\u6216\u4fee\u6539\u8868\u3002 LOW_PRIORITY WRITE\uff1a\u6392\u4ed6\u9501\uff0c\u4f46\u5728\u51fa\u73b0\u6b7b\u9501\u65f6\u4f18\u5148\u7ea7\u8f83\u4f4e\u3002 \u663e\u5f0f\u4f7f\u7528 LOCK TABLES\uff1a \u8981\u660e\u786e\u9501\u5b9a\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528 LOCK TABLES \u8bed\u53e5\uff0c\u5982\u4e0b\u6240\u793a\uff1a LOCK TABLES my_table READ; [&hellip;]<\/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-5144","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5144","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=5144"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5144\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}