{"id":5411,"date":"2024-11-14T08:42:48","date_gmt":"2024-11-14T00:42:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5411\/"},"modified":"2024-11-14T08:42:48","modified_gmt":"2024-11-14T00:42:48","slug":"mysql-42000%e5%88%b0%e5%ba%95%e6%80%8e%e4%b9%88%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5411\/","title":{"rendered":"mysql\u00a042000\u5230\u5e95\u600e\u4e48\u89e3\u51b3"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u89e3\u51b3 mysql \u9519\u8bef 42000\uff1f\u786e\u5b9a\u5bfc\u81f4\u9501\u7b49\u5f85\u7684\u67e5\u8be2\u3002\u4f7f\u7528\u7d22\u5f15\u4f18\u5316\u67e5\u8be2\uff0c\u51cf\u5c11\u9501\u8303\u56f4\u3002\u8c03\u6574\u9501\u8d85\u65f6\u8bbe\u7f6e\uff0c\u589e\u52a0\u9501\u8d85\u65f6\u65f6\u95f4\u3002\u589e\u52a0\u5e76\u53d1\u8fde\u63a5\u6570\uff0c\u51cf\u5c11\u9501\u7ade\u4e89\u3002\u91cd\u65b0\u8bbe\u8ba1\u6570\u636e\u5e93\u7ed3\u6784\uff0c\u51cf\u5c11\u9501\u4e89\u7528\u3002\u4f7f\u7528\u9501\u63d0\u793a\uff0c\u5f3a\u5236\u83b7\u5f97\u7279\u5b9a\u9501\u7c7b\u578b\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052811392322216.jpg\" class=\"aligncenter\" title=\"mysql\u00a042000\u5230\u5e95\u600e\u4e48\u89e3\u51b3\u63d2\u56fe\" alt=\"mysql\u00a042000\u5230\u5e95\u600e\u4e48\u89e3\u51b3\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u89e3\u51b3 MySQL \u9519\u8bef 42000<\/strong><\/p>\n<p>MySQL \u9519\u8bef 42000 \u901a\u5e38\u662f\u7531\u9501\u7b49\u5f85\u9020\u6210\u7684\u3002\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u5c1d\u8bd5\u83b7\u53d6\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u5df2\u6301\u6709\u7684\u9501\u65f6\uff0c\u5c31\u4f1a\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><strong>1. \u786e\u5b9a\u5bfc\u81f4\u9501\u7b49\u5f85\u7684\u67e5\u8be2<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 SHOW PROCESSLIST \u547d\u4ee4\u67e5\u770b\u6b63\u5728\u8fd0\u884c\u7684\u67e5\u8be2\u3002<\/li>\n<li>\u627e\u5230\u663e\u793a\u4e3a Waiting for table level lock \u6216 Waiting for lock release \u72b6\u6001\u7684\u67e5\u8be2\u3002<\/li>\n<li>\u7ec8\u6b62\u5f15\u8d77\u51b2\u7a81\u7684\u67e5\u8be2\u3002<\/li>\n<\/ul>\n<p><strong>2. \u4f18\u5316\u67e5\u8be2<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u7d22\u5f15\u6765\u907f\u514d\u5168\u8868\u626b\u63cf\u3002<\/li>\n<li>\u4f18\u5316\u67e5\u8be2\u6761\u4ef6\u4ee5\u51cf\u5c11\u9501\u7684\u8303\u56f4\u3002<\/li>\n<li>\u4f7f\u7528 EXPLAIN \u547d\u4ee4\u5206\u6790\u67e5\u8be2\u7684\u6267\u884c\u8ba1\u5212\uff0c\u5e76\u67e5\u627e\u53ef\u4ee5\u4f18\u5316\u7684\u5730\u65b9\u3002<\/li>\n<\/ul>\n<p><strong>3. \u8c03\u6574\u9501\u8d85\u65f6\u8bbe\u7f6e<\/strong><\/p>\n<ul>\n<li>\u66f4\u6539 innodb_lock_wait_timeout \u53d8\u91cf\u4ee5\u589e\u52a0\u9501\u8d85\u65f6\u65f6\u95f4\u3002<\/li>\n<li>\u8fd9\u53ef\u4ee5\u9632\u6b62\u7ebf\u7a0b\u957f\u65f6\u95f4\u7b49\u5f85\u9501\uff0c\u4f46\u5b83\u4e5f\u4f1a\u589e\u52a0\u6b7b\u9501\u7684\u98ce\u9669\u3002<\/li>\n<\/ul>\n<p><strong>4. \u589e\u52a0\u5e76\u53d1\u8fde\u63a5\u6570<\/strong><\/p>\n<ul>\n<li>\u8c03\u6574 max_connections \u53d8\u91cf\u4ee5\u589e\u52a0\u5141\u8bb8\u7684\u5e76\u53d1\u8fde\u63a5\u6570\u3002<\/li>\n<li>\u8fd9\u53ef\u4ee5\u51cf\u5c11\u540c\u65f6\u5c1d\u8bd5\u83b7\u53d6\u9501\u7684\u7ebf\u7a0b\u6570\u91cf\u3002<\/li>\n<\/ul>\n<p><strong>5. \u91cd\u65b0\u8bbe\u8ba1\u6570\u636e\u5e93\u7ed3\u6784<\/strong><\/p>\n<ul>\n<li>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u91cd\u65b0\u8bbe\u8ba1\u6570\u636e\u5e93\u7ed3\u6784\u53ef\u4ee5\u51cf\u5c11\u9501\u4e89\u7528\u3002<\/li>\n<li>\u4f8b\u5982\uff0c\u53ef\u4ee5\u5c06\u8868\u62c6\u5206\u4e3a\u591a\u4e2a\u66f4\u5c0f\u7684\u8868\uff0c\u6216\u8005\u4f7f\u7528\u5206\u533a\u3002<\/li>\n<\/ul>\n<p><strong>6. \u4f7f\u7528\u9501\u63d0\u793a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 SELECT &#8230; FOR UPDATE \u6216 SELECT &#8230; FOR SHARE \u9501\u63d0\u793a\u6765\u5f3a\u5236\u67e5\u8be2\u83b7\u5f97\u7279\u5b9a\u7684\u9501\u7c7b\u578b\u3002<\/li>\n<li>\u8fd9\u53ef\u4ee5\u5e2e\u52a9\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u9501\u4e89\u7528\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u4e0a\u8ff0\u65b9\u6cd5\u65e0\u6cd5\u89e3\u51b3\u95ee\u9898\uff0c\u5219\u53ef\u80fd\u9700\u8981\u8003\u8651\u5347\u7ea7 MySQL \u7248\u672c\u6216\u8054\u7cfb MySQL \u652f\u6301\u56e2\u961f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f&nbsp;42000\u5230\u5e95\u600e\u4e48\u89e3\u51b3\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>\u5982\u4f55\u89e3\u51b3 mysql \u9519\u8bef 42000\uff1f\u786e\u5b9a\u5bfc\u81f4\u9501\u7b49\u5f85\u7684\u67e5\u8be2\u3002\u4f7f\u7528\u7d22\u5f15\u4f18\u5316\u67e5\u8be2\uff0c\u51cf\u5c11\u9501\u8303\u56f4\u3002\u8c03\u6574\u9501\u8d85\u65f6\u8bbe\u7f6e\uff0c\u589e\u52a0\u9501\u8d85\u65f6\u65f6\u95f4\u3002\u589e\u52a0\u5e76\u53d1\u8fde\u63a5\u6570\uff0c\u51cf\u5c11\u9501\u7ade\u4e89\u3002\u91cd\u65b0\u8bbe\u8ba1\u6570\u636e\u5e93\u7ed3\u6784\uff0c\u51cf\u5c11\u9501\u4e89\u7528\u3002\u4f7f\u7528\u9501\u63d0\u793a\uff0c\u5f3a\u5236\u83b7\u5f97\u7279\u5b9a\u9501\u7c7b\u578b\u3002 \u5982\u4f55\u89e3\u51b3 MySQL \u9519\u8bef 42000 MySQL \u9519\u8bef 42000 \u901a\u5e38\u662f\u7531\u9501\u7b49\u5f85\u9020\u6210\u7684\u3002\u5f53\u4e00\u4e2a\u7ebf\u7a0b\u5c1d\u8bd5\u83b7\u53d6\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u5df2\u6301\u6709\u7684\u9501\u65f6\uff0c\u5c31\u4f1a\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a 1. \u786e\u5b9a\u5bfc\u81f4\u9501\u7b49\u5f85\u7684\u67e5\u8be2 \u4f7f\u7528 SHOW PROCESSLIST \u547d\u4ee4\u67e5\u770b\u6b63\u5728\u8fd0\u884c\u7684\u67e5\u8be2\u3002 \u627e\u5230\u663e\u793a\u4e3a Waiting for table level lock \u6216 Waiting for lock release \u72b6\u6001\u7684\u67e5\u8be2\u3002 \u7ec8\u6b62\u5f15\u8d77\u51b2\u7a81\u7684\u67e5\u8be2\u3002 2. \u4f18\u5316\u67e5\u8be2 \u4f7f\u7528\u7d22\u5f15\u6765\u907f\u514d\u5168\u8868\u626b\u63cf\u3002 \u4f18\u5316\u67e5\u8be2\u6761\u4ef6\u4ee5\u51cf\u5c11\u9501\u7684\u8303\u56f4\u3002 \u4f7f\u7528 EXPLAIN \u547d\u4ee4\u5206\u6790\u67e5\u8be2\u7684\u6267\u884c\u8ba1\u5212\uff0c\u5e76\u67e5\u627e\u53ef\u4ee5\u4f18\u5316\u7684\u5730\u65b9\u3002 3. \u8c03\u6574\u9501\u8d85\u65f6\u8bbe\u7f6e \u66f4\u6539 innodb_lock_wait_timeout \u53d8\u91cf\u4ee5\u589e\u52a0\u9501\u8d85\u65f6\u65f6\u95f4\u3002 \u8fd9\u53ef\u4ee5\u9632\u6b62\u7ebf\u7a0b\u957f\u65f6\u95f4\u7b49\u5f85\u9501\uff0c\u4f46\u5b83\u4e5f\u4f1a\u589e\u52a0\u6b7b\u9501\u7684\u98ce\u9669\u3002 4. \u589e\u52a0\u5e76\u53d1\u8fde\u63a5\u6570 \u8c03\u6574 max_connections \u53d8\u91cf\u4ee5\u589e\u52a0\u5141\u8bb8\u7684\u5e76\u53d1\u8fde\u63a5\u6570\u3002 \u8fd9\u53ef\u4ee5\u51cf\u5c11\u540c\u65f6\u5c1d\u8bd5\u83b7\u53d6\u9501\u7684\u7ebf\u7a0b\u6570\u91cf\u3002 5. \u91cd\u65b0\u8bbe\u8ba1\u6570\u636e\u5e93\u7ed3\u6784 \u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u91cd\u65b0\u8bbe\u8ba1\u6570\u636e\u5e93\u7ed3\u6784\u53ef\u4ee5\u51cf\u5c11\u9501\u4e89\u7528\u3002 \u4f8b\u5982\uff0c\u53ef\u4ee5\u5c06\u8868\u62c6\u5206\u4e3a\u591a\u4e2a\u66f4\u5c0f\u7684\u8868\uff0c\u6216\u8005\u4f7f\u7528\u5206\u533a\u3002 [&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-5411","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5411","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=5411"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5411\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}