{"id":491,"date":"2025-10-22T09:22:54","date_gmt":"2025-10-22T01:22:54","guid":{"rendered":"https:\/\/www.hyw.life\/?p=491"},"modified":"2025-10-22T09:31:24","modified_gmt":"2025-10-22T01:31:24","slug":"%e3%80%90%e5%bc%82%e5%b8%b8%e8%a7%a3%e5%86%b3%e3%80%91mysql%e6%95%b0%e6%8d%ae%e5%ba%93%ef%bc%9alock-wait-timeout-exceeded%ef%bc%9b-try-restarting-transaction%e9%97%ae%e9%a2%98%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.hyw.life\/?p=491","title":{"rendered":"\u3010\u5f02\u5e38\u89e3\u51b3\u3011MySQL\u6570\u636e\u5e93\uff1aLock wait timeout exceeded\uff1b try restarting transaction\u95ee\u9898\u89e3\u6790\u53ca\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"\n<span id=\"h3-0\" class=\"heading-anchor\" aria-hidden=\"true\"><\/span><h3 class=\"wp-block-heading\">\u9501\u7b49\u5f85\u8d85\u65f6\u51fa\u73b0\u7684\u60c5\u51b5<\/h3>\n\n\n\n<p>1\u3001\u591a\u53f0\u670d\u52a1\u5668\u540c\u65f6\u64cd\u4f5c\u540c\u4e00\u6570\u636e\u5e93\u3002<br>2\u3001\u5728\u540c\u4e00\u4e8b\u52a1\u5185\u5148\u540e\u5bf9\u540c\u4e00\u6761\u6570\u636e\u8fdb\u884c\u63d2\u5165\u548c\u66f4\u65b0\u64cd\u4f5c\u3002<br>3\u3001\u540c\u65f6\u5bf9\u540c\u4e00\u5f20\u8868\u8fdb\u884c\u63d2\u5165\u548c\u66f4\u65b0\u64cd\u4f5c\u3002<br>4\u3001\u4e8b\u52a1A\u5bf9\u8bb0\u5f55C\u8fdb\u884c\u66f4\u65b0\/\u5220\u9664\u64cd\u4f5c\u7684\u8bf7\u6c42\u672acommit\u65f6\uff0c\u4e8b\u52a1B\u4e5f\u5bf9\u8bb0\u5f55C\u8fdb\u884c\u66f4\u65b0\/\u5220\u9664\u64cd\u4f5c\u3002\u6b64\u65f6\uff0cB\u4f1a\u7b49A\u63d0\u4ea4\u4e8b\u52a1\uff0c\u91ca\u653e\u884c\u9501\u3002\u5f53\u7b49\u5f85\u65f6\u95f4\u8d85\u8fc7<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">innodb_lock_wait_timeout<\/mark>\u8bbe\u7f6e\u503c\u65f6\uff0c\u4f1a\u4ea7\u751f\u201cLOCK WAIT\u201d\u4e8b\u52a1\u3002<br>5\u3001\u6570\u636e\u5e93\u5185\u5b58\u4e0d\u8db3\uff0c\u5bfc\u81f4\u65e0\u6cd5\u6267\u884c\u5199\u64cd\u4f5c\u3002<br>6\u3001\u77ac\u65f6\u51fa\u73b0\u9ad8\u5e76\u53d1\u73b0\u8c61\uff0cSpring\u4e8b\u52a1\u9020\u6210\u6570\u636e\u5e93\u6b7b\u9501\uff0c\u540e\u7eed\u64cd\u4f5c\u8d85\u65f6\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n\n\n\n<span id=\"h3-1\" class=\"heading-anchor\" aria-hidden=\"true\"><\/span><h3 class=\"wp-block-heading\">\u89e3\u51b3\u65b9\u6848<\/h3>\n\n\n\n<p>\u53ef\u4ee5\u4f7f\u7528 information_schema \u67e5\u8be2\u6570\u636e\u5e93\u4f7f\u7528\u60c5\u51b5\u3002information_schema \u8fd9\u4e2a\u6570\u636e\u5e93\u4fdd\u5b58\u4e86 MySQL \u670d\u52a1\u5668\u6240\u6709\u6570\u636e\u5e93\u7684\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>\u5982\u6570\u636e\u5e93\u540d\uff0c\u6570\u636e\u5e93\u7684\u8868\uff0c\u8868\u680f\u7684\u6570\u636e\u7c7b\u578b\u4e0e\u8bbf\u95ee\u6743\u9650\u7b49\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u8fd9\u53f0 MySQL \u670d\u52a1\u5668\u4e0a\uff0c\u5230\u5e95\u6709\u54ea\u4e9b\u6570\u636e\u5e93\u3001\u5404\u4e2a\u6570\u636e\u5e93\u6709\u54ea\u4e9b\u8868\uff0c\u6bcf\u5f20\u8868\u7684\u5b57\u6bb5\u7c7b\u578b\u662f\u4ec0\u4e48\uff0c\u5404\u4e2a\u6570\u636e\u5e93\u8981\u4ec0\u4e48\u6743\u9650\u624d\u80fd\u8bbf\u95ee\u7b49\u7b49\u4fe1\u606f\u90fd\u4fdd\u5b58\u5728 information_schema \u5e93\u91cc\u9762\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\u3001SELECT * FROM information_schema.INNODB_TRX; \u2013 \u5f53\u524d\u8fd0\u884c\u7684\u6240\u6709\u4e8b\u52a1\n2\u3001SELECT * FROM information_schema.INNODB_LOCKS; \u2013 \u5f53\u524d\u51fa\u73b0\u7684\u9501\n3\u3001SELECT * FROM information_schema.INNODB_LOCK_WAITS; \u2013 \u9501\u7b49\u5f85\u7684\u5bf9\u5e94\u5173\u7cfb\n<\/code><\/pre>\n\n\n\n<span id=\"h3-2\" class=\"heading-anchor\" aria-hidden=\"true\"><\/span><h3 class=\"wp-block-heading\">\u65b9\u6848\u4e00 \u4e8b\u52a1\u4fe1\u606f\u67e5\u8be2<\/h3>\n\n\n\n<p>\u901a\u8fc7SELECT * FROM information_schema.innodb_trx\u67e5\u8be2\u672a\u63d0\u4ea4\u4e8b\u52a1\uff0c\u67e5\u5230\u4e00\u4e2a\u4e00\u76f4\u6ca1\u6709\u63d0\u4ea4\u7684\u53ea\u8bfb\u4e8b\u52a1\uff08trx_state=\u201dLOCK WAIT\u201d\uff09\uff0c\u627e\u5230\u5bf9\u5e94\u7ebf\u7a0b\uff0c\u6267\u884c\uff1akill \u7ebf\u7a0bID\u3002\u7ebf\u7a0bid\u4e3a\u8868\u4e2d\u7684trx_mysql_thread_id\u5b57\u6bb5\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6570\u636e\u5e93\u4e2d\u6709\u9501\u7684\u8bdd\uff0c\u67e5\u770b innodb_trx\u5c31\u53ef\u4ee5\u770b\u5230\u5bf9\u5e94\u7684\u4fe1\u606f\u3002\u901a\u8fc7\u67e5\u8be2\u77e5\u9053\u662f\u54ea\u6761\u8bed\u53e5\u9501\u4e86\uff0c\u56fe\u4e2d\u7ea2\u8272\u8bed\u53e5\u4e3a\u5360\u7528\u7cfb\u7edf\u8d44\u6e90\u7684\u8bed\u53e5\uff0c\u6211\u4eec\u9700\u8981\u6740\u6389\u8fd9\u4e2a\u9501\uff0c\u6267\u884c kill \u7ebf\u7a0bid\u53f7\u3002\u4e0a\u9762\u8fd9\u6761\u8bb0\u5f55\u7684id\u4e3a319618246 \uff0c\u6240\u4ee5\u6211\u4eec\u6267\u884c\uff1akill 319618246\u5373\u53ef\u3002\u4ee5\u4e0b\u4e3a\u6267\u884c\u524d\u540e\u5bf9\u6bd4\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image.png\"><a href=\"https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1533\" height=\"184\" src=\"https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image.png\" alt=\"\" class=\"wp-image-495\" srcset=\"https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image.png 1533w, https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image-300x36.png 300w, https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image-1024x123.png 1024w, https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image-768x92.png 768w\" sizes=\"auto, (max-width: 1533px) 100vw, 1533px\" \/><\/a><\/a><\/figure>\n\n\n\n<p>\u6267\u884c\u4ee5\u540e\u7684\u60c5\u51b5\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image-1.png\"><a href=\"https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1316\" height=\"152\" src=\"https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image-1.png\" alt=\"\" class=\"wp-image-496\" srcset=\"https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image-1.png 1316w, https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image-1-300x35.png 300w, https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image-1-1024x118.png 1024w, https:\/\/www.hyw.life\/wp-content\/uploads\/2025\/10\/image-1-768x89.png 768w\" sizes=\"auto, (max-width: 1316px) 100vw, 1316px\" \/><\/a><\/a><\/figure>\n\n\n\n<span id=\"h3-3\" class=\"heading-anchor\" aria-hidden=\"true\"><\/span><h3 class=\"wp-block-heading\"><strong>\u65b9\u6848\u4e8c<\/strong> <strong>\u5982\u679c\u6740\u6389\u7ebf\u7a0b\u4f9d\u7136\u4e0d\u80fd\u89e3\u51b3\uff0c\u53ef\u4ee5\u67e5\u627e\u6267\u884c\u7ebf\u7a0b\u8017\u65f6\u6bd4\u8f83\u4e45\u7684\u4efb\u52a1\uff0ckill\u6389<\/strong><\/h3>\n\n\n\n<p>\u6267\u884c<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">SELECT * from information_schema.PROCESSLIST WHERE Time > 1000 AND USER = \u2018xxx\u2019 ORDER BY TIME desc;<\/mark>\u627e\u5230\u7ebf\u7a0b\uff1akill \u7ebf\u7a0bID\u3002<\/p>\n\n\n\n<span id=\"h3-4\" class=\"heading-anchor\" aria-hidden=\"true\"><\/span><h3 class=\"wp-block-heading\"><strong>\u65b9\u6848\u4e09 innodb_lock_wait_timeout \u9501\u5b9a\u7b49\u5f85\u65f6\u95f4\u6539\u5927<\/strong><\/h3>\n\n\n\n<p>\u4fee\u6539\u8d85\u65f6\u65f6\u95f4\u5c06 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">#innodb_lock_wait_timeout = 50<\/mark> \u4fee\u6539\u4e3a <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">innodb_lock_wait_timeout = 500<\/mark>\u3002<\/p>\n\n\n\n<p>\u7f3a\u70b9\uff1a\u5168\u5c40\u66f4\u6539\uff0c\u5f71\u54cd\u4e5f\u662f\u5168\u5c40\u7684\uff0c\u7b49\u5f85\u65f6\u95f4\u52a0\u957f\uff0c\u5bb9\u6613\u4f7f\u7b49\u5f85\u4e8b\u52a1\u589e\u591a\u5bfc\u81f4\u5806\u79ef\u95ee\u9898\u3002<\/p>\n\n\n\n<span id=\"h3-5\" class=\"heading-anchor\" aria-hidden=\"true\"><\/span><h3 class=\"wp-block-heading\"><strong>\u65b9\u6848\u56db \u4f18\u5316SQL\u8bed\u53e5<\/strong><\/h3>\n\n\n\n<p>\u5bf9\u4e8e\u6211\u4e0a\u9762\u7684\u66f4\u65b0\u64cd\u4f5c\u7684\u5199\u6cd5\uff0c\u4f18\u5316\u4e86\u4e00\u4e0b\uff0c\u6548\u7387\u63d0\u9ad8\u4e8610\u500d\u5de6\u53f3\u3002\u4ee5\u4e0b\u662f\u4f18\u5316\u540e\u7684\u5199\u6cd5\uff1a<\/p>\n\n\n\n<p>\u5373\u5728\u6570\u636e\u5e93\u4e2d\u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u8868\uff08\u6bd4\u5982\u4e0b\u9762\u7684 t_test_a \u8868\uff09\uff0c\u7528\u4e8e\u5b58\u653e\u4e0a\u8ff0SQL\u8bed\u53e5\u4e2d\u67e5\u8be2\u51fa\u6765\u7684\u5b50\u7ed3\u679c\u907f\u514d\u4f7f\u7528IN\u5b57\u6bb5\u5bfc\u81f4\u626b\u63cf\u5168\u8868\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>UPDATE device_data_monitor ddm INNER JOIN t_test_a tta ON ddm.monitor_id = tta.monitor_id\nSET device_id = 45, pillar_id = 29, collect_id = 64<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9501\u7b49\u5f85\u8d85\u65f6\u51fa\u73b0\u7684\u60c5\u51b5 1\u3001\u591a\u53f0\u670d\u52a1\u5668\u540c\u65f6\u64cd\u4f5c\u540c\u4e00\u6570\u636e\u5e93\u30022\u3001\u5728\u540c\u4e00\u4e8b\u52a1\u5185\u5148\u540e\u5bf9\u540c\u4e00\u6761\u6570\u636e\u8fdb\u884c\u63d2\u5165\u548c\u66f4\u65b0\u64cd\u4f5c\u30023 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":488,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[40,41],"class_list":["post-491","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hd","tag-mysql","tag-41"],"_links":{"self":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts\/491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=491"}],"version-history":[{"count":4,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts\/491\/revisions"}],"predecessor-version":[{"id":498,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/posts\/491\/revisions\/498"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=\/wp\/v2\/media\/488"}],"wp:attachment":[{"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hyw.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}