{"id":5418,"date":"2024-11-14T12:30:23","date_gmt":"2024-11-14T04:30:23","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5418\/"},"modified":"2024-11-14T12:30:23","modified_gmt":"2024-11-14T04:30:23","slug":"mysql%e9%94%81%e8%a1%a8%e6%80%8e%e4%b9%88%e8%a7%a3%e9%94%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5418\/","title":{"rendered":"mysql\u9501\u8868\u600e\u4e48\u89e3\u9501"},"content":{"rendered":"<blockquote><p>\n  \u8981\u89e3\u9501 mysql \u4e2d\u9501\u5b9a\u7684\u8868\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u786e\u5b9a\u9501\u5b9a\u7684\u8868\uff1a\u4f7f\u7528 show processlist \u547d\u4ee4\u3002\u6740\u6389\u9501\u5b9a\u7ebf\u7a0b\uff1a\u4f7f\u7528 kill \u547d\u4ee4\u3002\u4f7f\u7528 unlock tables \u8bed\u53e5\uff1a\u4f7f\u7528 unlock tables \u8bed\u53e5\u89e3\u9501\u6240\u6709\u9501\u5b9a\u7684\u8868\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052812005174536.jpg\" class=\"aligncenter\" title=\"mysql\u9501\u8868\u600e\u4e48\u89e3\u9501\u63d2\u56fe\" alt=\"mysql\u9501\u8868\u600e\u4e48\u89e3\u9501\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u89e3\u9501 MySQL \u9501\u5b9a\u7684\u8868<\/strong><\/p>\n<p>MySQL \u4e2d\u7684\u9501\u8868\u64cd\u4f5c\u53ef\u4ee5\u9632\u6b62\u5bf9\u6570\u636e\u5e93\u6570\u636e\u7684\u4fee\u6539\u9020\u6210\u6570\u636e\u4e0d\u4e00\u81f4\u3002\u4f46\u662f\uff0c\u5982\u679c\u8868\u88ab\u610f\u5916\u9501\u4f4f\uff0c\u53ef\u80fd\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u51fa\u73b0\u95ee\u9898\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u89e3\u9501 MySQL \u4e2d\u7684\u9501\u5b9a\u7684\u8868\u3002<\/p>\n<p><strong>\u89e3\u9501\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><strong>1. \u786e\u5b9a\u9501\u5b9a\u7684\u8868\uff1a<\/strong><\/p>\n<pre>SHOW PROCESSLIST;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u547d\u4ee4\u5c06\u663e\u793a\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684\u7ebf\u7a0b\u5217\u8868\uff0c\u5305\u62ec\u88ab\u9501\u5b9a\u7684\u8868\u7684\u76f8\u5173\u4fe1\u606f\u3002<\/p>\n<p><strong>2. \u6740\u6389\u9501\u5b9a\u7ebf\u7a0b\uff1a<\/strong><\/p>\n<pre>KILL &lt;\u7ebf\u7a0bID&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\u662f\u9501\u4f4f\u8868\u7684\u7ebf\u7a0b\u7684 ID\u3002<\/p>\n<p><strong>3. \u4f7f\u7528 UNLOCK TABLES \u8bed\u53e5\uff1a<\/strong><\/p>\n<pre>UNLOCK TABLES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u8bed\u53e5\u5c06\u89e3\u9501\u6240\u6709\u5f53\u524d\u88ab\u9501\u5b9a\u7684\u8868\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u786e\u5b9a\u9501\u5b9a\u7684\u8868\uff1a<\/strong>SHOW PROCESSLIST \u547d\u4ee4\u5c06\u663e\u793a\u4e00\u4e2a\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e0e\u6b63\u5728\u8fd0\u884c\u7684\u7ebf\u7a0b\u76f8\u5173\u7684\u6240\u6709\u4fe1\u606f\u3002\u72b6\u6001\u5217\u5c06\u663e\u793a\u7ebf\u7a0b\u7684\u5f53\u524d\u72b6\u6001\uff0c\u5982\u679c\u8868\u5df2\u9501\u4f4f\uff0c\u5219\u72b6\u6001\u5c06\u4e3a &#8220;Locked&#8221;\u3002<\/li>\n<li> <strong>\u6740\u6389\u9501\u5b9a\u7ebf\u7a0b\uff1a<\/strong>KILL \u547d\u4ee4\u5c06\u7ec8\u6b62\u6307\u5b9a\u7684\u7ebf\u7a0b\u3002\u5982\u679c\u9501\u5b9a\u8868\u7684\u662f\u9519\u8bef\u6216\u6302\u8d77\u7684\u7ebf\u7a0b\uff0c\u5219\u8fd9\u662f\u89e3\u9501\u8868\u7684\u6700\u7b80\u5355\u65b9\u6cd5\u3002\u4f46\u662f\uff0c\u5982\u679c\u7ebf\u7a0b\u6b63\u5728\u6267\u884c\u5173\u952e\u4efb\u52a1\uff0c\u5219\u7ec8\u6b62\u7ebf\u7a0b\u53ef\u80fd\u4f1a\u5bfc\u81f4\u3002<\/li>\n<li> <strong>\u4f7f\u7528 UNLOCK TABLES \u8bed\u53e5\uff1a<\/strong>UNLOCK TABLES \u8bed\u53e5\u5c06\u89e3\u9501\u6240\u6709\u5f53\u524d\u88ab\u9501\u5b9a\u7684\u8868\u3002\u8fd9\u662f\u89e3\u9501\u8868\u7684\u63a8\u8350\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4f1a\u7ec8\u6b62\u4efb\u4f55\u7ebf\u7a0b\uff0c\u4ece\u800c\u964d\u4f4e\u6570\u636e\u4e22\u5931\u7684\u98ce\u9669\u3002<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u89e3\u9501\u8868\u540e\uff0c\u5176\u4ed6\u7ebf\u7a0b\u53ef\u4ee5\u7acb\u5373\u83b7\u5f97\u5bf9\u8868\u7684\u8bbf\u95ee\u6743\u9650\uff0c\u56e0\u6b64\u5728\u89e3\u9501\u8868\u4e4b\u524d\u5b8c\u6210\u6240\u6709\u5fc5\u8981\u7684\u4fee\u6539\u975e\u5e38\u91cd\u8981\u3002<\/li>\n<li>\u5207\u52ff\u4f7f\u7528 FLUSH TABLES WITH READ LOCK \u6216 LOCK TABLES \u547d\u4ee4\u6765\u89e3\u51b3\u9501\u5b9a\u95ee\u9898\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6b7b\u9501\u5e76\u4f7f\u6570\u636e\u5e93\u65e0\u6cd5\u8bbf\u95ee\u3002<\/li>\n<li>\u5982\u679c\u65e0\u6cd5\u89e3\u9501\u8868\uff0c\u8bf7\u8054\u7cfb\u6570\u636e\u5e93\u7ba1\u7406\u5458\u5bfb\u6c42\u5e2e\u52a9\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u9501\u8868\u600e\u4e48\u89e3\u9501\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>\u8981\u89e3\u9501 mysql \u4e2d\u9501\u5b9a\u7684\u8868\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u786e\u5b9a\u9501\u5b9a\u7684\u8868\uff1a\u4f7f\u7528 show processlist \u547d\u4ee4\u3002\u6740\u6389\u9501\u5b9a\u7ebf\u7a0b\uff1a\u4f7f\u7528 kill \u547d\u4ee4\u3002\u4f7f\u7528 unlock tables \u8bed\u53e5\uff1a\u4f7f\u7528 unlock tables \u8bed\u53e5\u89e3\u9501\u6240\u6709\u9501\u5b9a\u7684\u8868\u3002 \u5982\u4f55\u89e3\u9501 MySQL \u9501\u5b9a\u7684\u8868 MySQL \u4e2d\u7684\u9501\u8868\u64cd\u4f5c\u53ef\u4ee5\u9632\u6b62\u5bf9\u6570\u636e\u5e93\u6570\u636e\u7684\u4fee\u6539\u9020\u6210\u6570\u636e\u4e0d\u4e00\u81f4\u3002\u4f46\u662f\uff0c\u5982\u679c\u8868\u88ab\u610f\u5916\u9501\u4f4f\uff0c\u53ef\u80fd\u5bfc\u81f4\u5e94\u7528\u7a0b\u5e8f\u51fa\u73b0\u95ee\u9898\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u89e3\u9501 MySQL \u4e2d\u7684\u9501\u5b9a\u7684\u8868\u3002 \u89e3\u9501\u65b9\u6cd5\uff1a 1. \u786e\u5b9a\u9501\u5b9a\u7684\u8868\uff1a SHOW PROCESSLIST; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u547d\u4ee4\u5c06\u663e\u793a\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684\u7ebf\u7a0b\u5217\u8868\uff0c\u5305\u62ec\u88ab\u9501\u5b9a\u7684\u8868\u7684\u76f8\u5173\u4fe1\u606f\u3002 2. \u6740\u6389\u9501\u5b9a\u7ebf\u7a0b\uff1a KILL &lt;\u7ebf\u7a0bID&gt;; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\u662f\u9501\u4f4f\u8868\u7684\u7ebf\u7a0b\u7684 ID\u3002 3. \u4f7f\u7528 UNLOCK TABLES \u8bed\u53e5\uff1a UNLOCK TABLES; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u8bed\u53e5\u5c06\u89e3\u9501\u6240\u6709\u5f53\u524d\u88ab\u9501\u5b9a\u7684\u8868\u3002 \u8be6\u7ec6\u8bf4\u660e\uff1a \u786e\u5b9a\u9501\u5b9a\u7684\u8868\uff1aSHOW PROCESSLIST \u547d\u4ee4\u5c06\u663e\u793a\u4e00\u4e2a\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e0e\u6b63\u5728\u8fd0\u884c\u7684\u7ebf\u7a0b\u76f8\u5173\u7684\u6240\u6709\u4fe1\u606f\u3002\u72b6\u6001\u5217\u5c06\u663e\u793a\u7ebf\u7a0b\u7684\u5f53\u524d\u72b6\u6001\uff0c\u5982\u679c\u8868\u5df2\u9501\u4f4f\uff0c\u5219\u72b6\u6001\u5c06\u4e3a &#8220;Locked&#8221;\u3002 \u6740\u6389\u9501\u5b9a\u7ebf\u7a0b\uff1aKILL \u547d\u4ee4\u5c06\u7ec8\u6b62\u6307\u5b9a\u7684\u7ebf\u7a0b\u3002\u5982\u679c\u9501\u5b9a\u8868\u7684\u662f\u9519\u8bef\u6216\u6302\u8d77\u7684\u7ebf\u7a0b\uff0c\u5219\u8fd9\u662f\u89e3\u9501\u8868\u7684\u6700\u7b80\u5355\u65b9\u6cd5\u3002\u4f46\u662f\uff0c\u5982\u679c\u7ebf\u7a0b\u6b63\u5728\u6267\u884c\u5173\u952e\u4efb\u52a1\uff0c\u5219\u7ec8\u6b62\u7ebf\u7a0b\u53ef\u80fd\u4f1a\u5bfc\u81f4\u3002 \u4f7f\u7528 UNLOCK TABLES \u8bed\u53e5\uff1aUNLOCK [&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-5418","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5418","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=5418"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5418\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}