{"id":6436,"date":"2024-11-14T13:11:15","date_gmt":"2024-11-14T05:11:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6436\/"},"modified":"2024-11-14T13:11:15","modified_gmt":"2024-11-14T05:11:15","slug":"mysql%e6%9f%a5%e8%af%a2%e9%94%81%e8%a1%a8%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6436\/","title":{"rendered":"mysql\u67e5\u8be2\u9501\u8868\u8bed\u53e5"},"content":{"rendered":"<blockquote><p>\n  mysql \u63d0\u4f9b\u4ee5\u4e0b\u663e\u5f0f\u9501\u8868\u8bed\u53e5\uff1alock tables\uff1a\u7528\u4e8e\u663e\u5f0f\u9501\u8868\uff0c\u8bed\u6cd5\u4e3a\uff1alock tables table_name[as lock_alias] [mode] [timeout]\u89e3\u9501\uff1a\u4f7f\u7528 unlock tables \u8bed\u53e5\u91ca\u653e\u9501\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/02\/2024080220253278208.jpg\" class=\"aligncenter\" title=\"mysql\u67e5\u8be2\u9501\u8868\u8bed\u53e5\u63d2\u56fe\" alt=\"mysql\u67e5\u8be2\u9501\u8868\u8bed\u53e5\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u67e5\u8be2\u9501\u8868\u8bed\u53e5<\/strong><\/p>\n<p>MySQL \u63d0\u4f9b\u4e86 LOCK TABLES \u8bed\u53e5\u6765\u663e\u5f0f\u9501\u8868\uff0c\u8be5\u8bed\u53e5\u53ef\u786e\u4fdd\u5728\u6267\u884c\u5176\u4ed6\u67e5\u8be2\u6216\u66f4\u65b0\u65f6\uff0c\u88ab\u9501\u5b9a\u7684\u8868\u53ea\u80fd\u88ab\u5f53\u524d\u4f1a\u8bdd\u8bbf\u95ee\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<p>LOCK TABLES table_name [, &#8230;] [AS lock_alias] [mode] [timeout]<\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>table_name: \u8981\u9501\u5b9a\u7684\u8868\u540d<\/li>\n<li>lock_alias: \u53ef\u9009\u7684\u522b\u540d\uff0c\u7528\u4e8e\u5728 UNLOCK TABLES \u8bed\u53e5\u4e2d\u5f15\u7528\u9501<\/li>\n<li>mode: \u9501\u5b9a\u6a21\u5f0f\uff08\u89c1\u4e0b\u6587\uff09<\/li>\n<li>timeout: \u53ef\u9009\u7684\u8d85\u65f6\u503c\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09<\/li>\n<\/ul>\n<p><strong>\u9501\u5b9a\u6a21\u5f0f<\/strong><\/p>\n<p>MySQL \u63d0\u4f9b\u4e86\u4ee5\u4e0b\u9501\u5b9a\u6a21\u5f0f\uff1a<\/p>\n<ul>\n<li>READ: \u5141\u8bb8\u5f53\u524d\u4f1a\u8bdd\u8bfb\u53d6\u8868\uff0c\u4f46\u5176\u4ed6\u4f1a\u8bdd\u65e0\u6cd5\u4fee\u6539\u8868\u3002<\/li>\n<li>WRITE: \u5141\u8bb8\u5f53\u524d\u4f1a\u8bdd\u5199\u5165\u8868\uff0c\u5e76\u4e14\u963b\u585e\u5176\u4ed6\u4f1a\u8bdd\u5bf9\u8868\u7684\u4efb\u4f55\u8bbf\u95ee\u3002<\/li>\n<li>LOW_PRIORITY WRITE: \u5c1d\u8bd5\u83b7\u53d6\u9501\uff0c\u4f46\u5982\u679c\u5176\u4ed6\u4f1a\u8bdd\u5df2\u83b7\u53d6\u9501\uff0c\u5219\u653e\u5f03\u5e76\u7b49\u5f85\u91ca\u653e\u9501\u3002<\/li>\n<li>NOWAIT: \u5c1d\u8bd5\u83b7\u53d6\u9501\uff0c\u4f46\u5982\u679c\u5176\u4ed6\u4f1a\u8bdd\u5df2\u83b7\u53d6\u9501\uff0c\u5219\u7acb\u5373\u8fd4\u56de\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u8981\u4ee5\u72ec\u5360\u6a21\u5f0f\u9501\u5b9a users \u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>LOCK TABLES users WRITE;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u4ee5\u5171\u4eab\u6a21\u5f0f\u9501\u5b9a\u591a\u4e2a\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>LOCK TABLES users READ, posts READ AS posts_alias;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8d85\u65f6<\/strong><\/p>\n<p>timeout \u53c2\u6570\u6307\u5b9a\u5728\u83b7\u53d6\u9501\u4e4b\u524d\u7b49\u5f85\u7684\u79d2\u6570\u3002\u5982\u679c\u5728\u8d85\u65f6\u4e4b\u524d\u672a\u83b7\u53d6\u9501\uff0c\u5219 LOCK TABLES \u8bed\u53e5\u5c06\u5931\u8d25\u5e76\u8fd4\u56de\u9519\u8bef\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>LOCK TABLES users WRITE TIMEOUT 10;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u91ca\u653e\u9501<\/strong><\/p>\n<p>\u4f7f\u7528 UNLOCK TABLES \u8bed\u53e5\u91ca\u653e\u9501\uff1a<\/p>\n<pre>UNLOCK TABLES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u9501\u8868\u4f1a\u963b\u6b62\u5176\u4ed6\u4f1a\u8bdd\u8bbf\u95ee\u8868\uff0c\u56e0\u6b64\u5e94\u8c28\u614e\u4f7f\u7528\u3002<\/li>\n<li>\u9501\u5b9a\u7684\u8868\u4e0d\u80fd\u88ab\u91cd\u547d\u540d\u3001\u5220\u9664\u6216\u622a\u65ad\u3002<\/li>\n<li>\u5982\u679c\u4f1a\u8bdd\u610f\u5916\u7ec8\u6b62\uff0c\u5219\u6240\u83b7\u53d6\u7684\u9501\u5c06\u81ea\u52a8\u91ca\u653e\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u67e5\u8be2\u9501\u8868\u8bed\u53e5\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 \u63d0\u4f9b\u4ee5\u4e0b\u663e\u5f0f\u9501\u8868\u8bed\u53e5\uff1alock tables\uff1a\u7528\u4e8e\u663e\u5f0f\u9501\u8868\uff0c\u8bed\u6cd5\u4e3a\uff1alock tables table_name[as lock_alias] [mode] [timeout]\u89e3\u9501\uff1a\u4f7f\u7528 unlock tables \u8bed\u53e5\u91ca\u653e\u9501\u3002 MySQL \u67e5\u8be2\u9501\u8868\u8bed\u53e5 MySQL \u63d0\u4f9b\u4e86 LOCK TABLES \u8bed\u53e5\u6765\u663e\u5f0f\u9501\u8868\uff0c\u8be5\u8bed\u53e5\u53ef\u786e\u4fdd\u5728\u6267\u884c\u5176\u4ed6\u67e5\u8be2\u6216\u66f4\u65b0\u65f6\uff0c\u88ab\u9501\u5b9a\u7684\u8868\u53ea\u80fd\u88ab\u5f53\u524d\u4f1a\u8bdd\u8bbf\u95ee\u3002 \u8bed\u6cd5 LOCK TABLES table_name [, &#8230;] [AS lock_alias] [mode] [timeout] \u5176\u4e2d\uff1a table_name: \u8981\u9501\u5b9a\u7684\u8868\u540d lock_alias: \u53ef\u9009\u7684\u522b\u540d\uff0c\u7528\u4e8e\u5728 UNLOCK TABLES \u8bed\u53e5\u4e2d\u5f15\u7528\u9501 mode: \u9501\u5b9a\u6a21\u5f0f\uff08\u89c1\u4e0b\u6587\uff09 timeout: \u53ef\u9009\u7684\u8d85\u65f6\u503c\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09 \u9501\u5b9a\u6a21\u5f0f MySQL \u63d0\u4f9b\u4e86\u4ee5\u4e0b\u9501\u5b9a\u6a21\u5f0f\uff1a READ: \u5141\u8bb8\u5f53\u524d\u4f1a\u8bdd\u8bfb\u53d6\u8868\uff0c\u4f46\u5176\u4ed6\u4f1a\u8bdd\u65e0\u6cd5\u4fee\u6539\u8868\u3002 WRITE: \u5141\u8bb8\u5f53\u524d\u4f1a\u8bdd\u5199\u5165\u8868\uff0c\u5e76\u4e14\u963b\u585e\u5176\u4ed6\u4f1a\u8bdd\u5bf9\u8868\u7684\u4efb\u4f55\u8bbf\u95ee\u3002 LOW_PRIORITY WRITE: \u5c1d\u8bd5\u83b7\u53d6\u9501\uff0c\u4f46\u5982\u679c\u5176\u4ed6\u4f1a\u8bdd\u5df2\u83b7\u53d6\u9501\uff0c\u5219\u653e\u5f03\u5e76\u7b49\u5f85\u91ca\u653e\u9501\u3002 NOWAIT: \u5c1d\u8bd5\u83b7\u53d6\u9501\uff0c\u4f46\u5982\u679c\u5176\u4ed6\u4f1a\u8bdd\u5df2\u83b7\u53d6\u9501\uff0c\u5219\u7acb\u5373\u8fd4\u56de\u9519\u8bef\u3002 \u793a\u4f8b \u8981\u4ee5\u72ec\u5360\u6a21\u5f0f\u9501\u5b9a users [&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-6436","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6436","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=6436"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6436\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}