{"id":5529,"date":"2014-04-11T16:35:40","date_gmt":"2014-04-11T08:35:40","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=5529"},"modified":"2014-04-11T16:35:40","modified_gmt":"2014-04-11T08:35:40","slug":"django%e4%bf%ae%e6%94%b9%e8%a1%a8%e7%bb%93%e6%9e%84%e5%af%bc%e8%87%b4mysql%e8%a1%a8%e9%94%81%e6%ad%bbwaiting-for-meta-lock%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/5529.html","title":{"rendered":"Django\u4fee\u6539\u8868\u7ed3\u6784\u5bfc\u81f4MySQL\u8868\u9501\u6b7bwaiting for meta lock\u7684\u95ee\u9898"},"content":{"rendered":"<p>\u6700\u8fd1\u6211\u4eec\u5728\u4f7f\u7528south\u5bf9django\u505aschemaigration\u7684\u8fc7\u7a0b\uff0c\u7ecf\u5e38\u9047\u5230mysql\u9501\u6b7b\u201cwaiting for meta lock\u201d\u7684\u73b0\u8c61\u3002<\/p>\n<p>\u8fd9\u79cd\u5e94\u8be5\u662fmysql\u5185\u91cc\u6709\u957f\u65f6\u95f4\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\uff0c\u7136\u540e\u53bb\u505aalter table\u7684\u65f6\u5019\u4f1a\u7b49\u5f85\u4e8b\u52a1\u63d0\u4ea4\uff0c\u8fd9\u6837\u4e00\u6765\u5c31\u9501\u6b7b\u4e86\uff0c\u8fde\u8bbf\u95ee\u8868\u90fd\u4e0d\u884c\u3002<\/p>\n<p>\u901a\u8fc7 select * from information_schema.innodb_trx\\G; \u67e5\u770b\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\uff0c\u53d1\u73b0\u7a0b\u5e8f\u4e00\u542f\u52a8\u5c31\u6709\u51e0\u4e2a\u957f\u671f\u5728\u90a3\u91cc\uff0c\u72b6\u6001\u4e00\u76f4\u662fRUNING\u3002<\/p>\n<p>\u76d1\u63a7mysql\u7684sql log\u53d1\u73b0\u542f\u52a8\u7a0b\u5e8f\u540e\u4f1a\u6267\u884c\u8fd9\u4e48\u51e0\u4e2a\u547d\u4ee4\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n263 Query\tSET NAMES utf8\r\n263 Query\tset autocommit=0\r\n263 Query\tSET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;SET NAMES utf8mb4\r\n263 Query\tSET SQL_AUTO_IS_NULL = 0\r\n<\/pre>\n<p>\u5173\u952e\u5728\u90a3\u4e2a set autocommit=0<\/p>\n<p>\u540e\u9762\u90a3\u4e2a\u662f\u6211\u4eec\u5728Django\u7684settings DATABASES default \u8282\u70b9\u91cc\u9762\u52a0\u7684\uff1a<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n'OPTIONS': { &quot;init_command&quot;: &quot;SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED&quot;, &quot;charset&quot;:&quot;utf8mb4&quot;},\r\n<\/pre>\n<p>\u6700\u540e\u627e\u5230\u662f MySQL-python \u5e93\u7684\u95ee\u9898\uff0c1.2.4 \u7248\u672c\u4e2d\u5f3a\u5236\u8bbe\u7f6e\u4e86 autocommit=False\uff0c\u65b0\u7248\u672c\u4e2d\u52a0\u5165\u4e86\u53c2\u6570\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e86\u3002\u5177\u4f53\u53ef\u4ee5\u770b connections.py \u4e2d reconnection \u65b9\u6cd5\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u6240\u4ee5\u5347\u7ea7\u52301.2.5\u540e\uff0c\u518d\u5728django\u7684 DATABASES default \u52a0\u4e2aOPTIONS\u5c31\u597d\u4e86\uff1a<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n'OPTIONS': { &quot;init_command&quot;: &quot;SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED&quot;, &quot;charset&quot;:&quot;utf8mb4&quot;, 'autocommit': True },\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u6211\u4eec\u5728\u4f7f\u7528south\u5bf9django\u505aschemaigration\u7684\u8fc7\u7a0b\uff0c\u7ecf\u5e38\u9047\u5230mysql\u9501\u6b7b\u201cwaiti [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-5529","post","type-post","status-publish","format-standard","hentry","category-diary"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/5529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=5529"}],"version-history":[{"count":2,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/5529\/revisions"}],"predecessor-version":[{"id":5531,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/5529\/revisions\/5531"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=5529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=5529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=5529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}