{"id":7849,"date":"2024-11-14T10:06:16","date_gmt":"2024-11-14T02:06:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7849\/"},"modified":"2024-11-14T10:06:16","modified_gmt":"2024-11-14T02:06:16","slug":"mysql-%e4%ba%8b%e5%8a%a1%e4%b8%ad%e7%9a%84-rollback%ef%bc%9a%e4%bd%95%e6%97%b6%e5%bf%85%e9%a1%bb%e6%89%a7%e8%a1%8c%ef%bc%8c%e4%bd%95%e6%97%b6%e5%8f%af%e4%bb%a5%e7%9c%81%e7%95%a5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7849\/","title":{"rendered":"MySQL \u4e8b\u52a1\u4e2d\u7684 Rollback\uff1a\u4f55\u65f6\u5fc5\u987b\u6267\u884c\uff0c\u4f55\u65f6\u53ef\u4ee5\u7701\u7565\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173129924824949.jpg\" class=\"aligncenter\" title=\"MySQL \u4e8b\u52a1\u4e2d\u7684 Rollback\uff1a\u4f55\u65f6\u5fc5\u987b\u6267\u884c\uff0c\u4f55\u65f6\u53ef\u4ee5\u7701\u7565\uff1f\u63d2\u56fe\" alt=\"MySQL \u4e8b\u52a1\u4e2d\u7684 Rollback\uff1a\u4f55\u65f6\u5fc5\u987b\u6267\u884c\uff0c\u4f55\u65f6\u53ef\u4ee5\u7701\u7565\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5173\u4e8e  \u4e8b\u52a1\u4e2d\u7684 rollback \u662f\u5426\u5fc5\u8981<\/strong><\/p>\n<p>\u5728 mysql \u4e8b\u52a1\u4e2d\uff0c\u7ecf\u5e38\u4f1a\u6709\u8fd9\u6837\u7684\u7591\u95ee\uff1a\u5f53\u4e8b\u52a1\u4e2d\u53d1\u751f\u5f02\u5e38\u65f6\uff0c\u662f\u5426\u5fc5\u987b\u8fdb\u884c rollback \u64cd\u4f5c\uff1f<\/p>\n<p><strong>\u4e8b\u52a1\u7684\u539f\u7406<\/strong><\/p>\n<p>\u4e8b\u52a1\u662f\u4e00\u4e2a\u539f\u5b50\u6027\u64cd\u4f5c\uff0c\u8981\u4e48\u5168\u90e8\u6267\u884c\u6210\u529f\uff0c\u8981\u4e48\u5168\u90e8\u5931\u8d25\u56de\u6eda\u3002\u5f00\u542f\u4e8b\u52a1\u65f6\uff0cmysql \u4f1a\u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u7a7a\u95f4\u6765\u4fdd\u5b58\u6240\u6709\u4fee\u6539\uff0c\u76f4\u5230\u4e8b\u52a1\u63d0\u4ea4 (commit) \u540e\uff0c\u8fd9\u4e9b\u4fee\u6539\u624d\u4f1a\u771f\u6b63\u5e94\u7528\u5230\u6570\u636e\u5e93\u4e2d\u3002<\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u7801<\/strong><\/p>\n<p>\u4f60\u7ed9\u51fa\u7684\u793a\u4f8b\u4ee3\u7801\u662f\u4e00\u4e2a\u5305\u542b\u4ee5\u4e0b\u64cd\u4f5c\u7684\u4e8b\u52a1\uff1a<\/p>\n<pre>START TRANSACTION;\nupdate temp2 set username=\"user2\" where id=1;\nupdate temp2 set username=\"user2\" where id=2;\nCOMMIT;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65e0\u9700 rollback \u7684\u60c5\u51b5<\/strong><\/p>\n<p>\u4f60\u63d0\u5230\u4e86\uff0c\u53ea\u8981\u6ca1\u6709\u6267\u884c commit\uff0c\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u5c31\u4e0d\u4f1a\u66f4\u65b0\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4e8b\u52a1\u5728\u6267\u884c\u66f4\u65b0\u8bed\u53e5\u4e4b\u524d\u53d1\u751f\u5f02\u5e38\uff0c\u5219\u6570\u636e\u4e0d\u4f1a\u53d1\u751f\u4efb\u4f55\u53d8\u5316\uff0c\u6b64\u65f6\u786e\u5b9e\u4e0d\u9700\u8981\u8fdb\u884c rollback\u3002<\/p>\n<p><strong>\u9700\u8981 rollback \u7684\u60c5\u51b5<\/strong><\/p>\n<p>\u4f46\u662f\uff0c\u5373\u4f7f\u65e0\u9700\u66f4\u65b0\u6570\u636e\uff0c\u4e5f\u4f9d\u7136\u9700\u8981\u6267\u884c rollback\u3002\u8fd9\u662f\u56e0\u4e3a\uff1a<\/p>\n<ul>\n<li> <strong>\u91ca\u653e\u9501\u5b9a\u7684\u8d44\u6e90\uff1a<\/strong>\u4e8b\u52a1\u5f00\u59cb\u540e\uff0cmysql \u4f1a\u5bf9\u6d89\u53ca\u5230\u7684\u8868\u8fdb\u884c\u52a0\u9501\uff0c\u4ee5\u9632\u6b62\u5176\u4ed6\u4e8b\u52a1\u3002\u5982\u679c\u6ca1\u6709\u6267\u884c rollback\uff0c\u8fd9\u4e9b\u9501\u5c06\u4e00\u76f4\u4fdd\u6301\uff0c\u4ece\u800c\u5bfc\u81f4\u6b7b\u9501\u6216\u6027\u80fd\u95ee\u9898\u3002<\/li>\n<li> <strong>\u7ed3\u675f\u4e8b\u52a1\u72b6\u6001\uff1a<\/strong>\u4e8b\u52a1\u72b6\u6001\u4f1a\u4e00\u76f4\u4fdd\u6301\uff0c\u76f4\u5230\u6267\u884c commit \u6216 rollback\u3002\u5982\u679c\u4e0d\u7ed3\u675f\u4e8b\u52a1\uff0c\u5927\u91cf\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\u4f1a\u963b\u585e\u6570\u636e\u5e93\u8d44\u6e90\uff0c\u5bfc\u81f4 idle in transaction \u7d2f\u79ef\uff0c\u4ece\u800c\u964d\u4f4e\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p>\u56e0\u6b64\uff0c\u65e0\u8bba\u4e8b\u52a1\u662f\u5426\u6210\u529f\uff0c\u90fd\u5e94\u53ca\u65f6\u6267\u884c commit \u6216 rollback \u4ee5\u91ca\u653e\u9501\u5b9a\u7684\u8d44\u6e90\u5e76\u7ed3\u675f\u4e8b\u52a1\u72b6\u6001\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u4e8b\u52a1\u4e2d\u7684 Rollback\uff1a\u4f55\u65f6\u5fc5\u987b\u6267\u884c\uff0c\u4f55\u65f6\u53ef\u4ee5\u7701\u7565\uff1f\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>\u5173\u4e8e \u4e8b\u52a1\u4e2d\u7684 rollback \u662f\u5426\u5fc5\u8981 \u5728 mysql \u4e8b\u52a1\u4e2d\uff0c\u7ecf\u5e38\u4f1a\u6709\u8fd9\u6837\u7684\u7591\u95ee\uff1a\u5f53\u4e8b\u52a1\u4e2d\u53d1\u751f\u5f02\u5e38\u65f6\uff0c\u662f\u5426\u5fc5\u987b\u8fdb\u884c rollback \u64cd\u4f5c\uff1f \u4e8b\u52a1\u7684\u539f\u7406 \u4e8b\u52a1\u662f\u4e00\u4e2a\u539f\u5b50\u6027\u64cd\u4f5c\uff0c\u8981\u4e48\u5168\u90e8\u6267\u884c\u6210\u529f\uff0c\u8981\u4e48\u5168\u90e8\u5931\u8d25\u56de\u6eda\u3002\u5f00\u542f\u4e8b\u52a1\u65f6\uff0cmysql \u4f1a\u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u7a7a\u95f4\u6765\u4fdd\u5b58\u6240\u6709\u4fee\u6539\uff0c\u76f4\u5230\u4e8b\u52a1\u63d0\u4ea4 (commit) \u540e\uff0c\u8fd9\u4e9b\u4fee\u6539\u624d\u4f1a\u771f\u6b63\u5e94\u7528\u5230\u6570\u636e\u5e93\u4e2d\u3002 \u793a\u4f8b\u4ee3\u7801 \u4f60\u7ed9\u51fa\u7684\u793a\u4f8b\u4ee3\u7801\u662f\u4e00\u4e2a\u5305\u542b\u4ee5\u4e0b\u64cd\u4f5c\u7684\u4e8b\u52a1\uff1a START TRANSACTION; update temp2 set username=&#8221;user2&#8243; where id=1; update temp2 set username=&#8221;user2&#8243; where id=2; COMMIT; \u767b\u5f55\u540e\u590d\u5236 \u65e0\u9700 rollback \u7684\u60c5\u51b5 \u4f60\u63d0\u5230\u4e86\uff0c\u53ea\u8981\u6ca1\u6709\u6267\u884c commit\uff0c\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u5c31\u4e0d\u4f1a\u66f4\u65b0\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4e8b\u52a1\u5728\u6267\u884c\u66f4\u65b0\u8bed\u53e5\u4e4b\u524d\u53d1\u751f\u5f02\u5e38\uff0c\u5219\u6570\u636e\u4e0d\u4f1a\u53d1\u751f\u4efb\u4f55\u53d8\u5316\uff0c\u6b64\u65f6\u786e\u5b9e\u4e0d\u9700\u8981\u8fdb\u884c rollback\u3002 \u9700\u8981 rollback \u7684\u60c5\u51b5 \u4f46\u662f\uff0c\u5373\u4f7f\u65e0\u9700\u66f4\u65b0\u6570\u636e\uff0c\u4e5f\u4f9d\u7136\u9700\u8981\u6267\u884c rollback\u3002\u8fd9\u662f\u56e0\u4e3a\uff1a \u91ca\u653e\u9501\u5b9a\u7684\u8d44\u6e90\uff1a\u4e8b\u52a1\u5f00\u59cb\u540e\uff0cmysql \u4f1a\u5bf9\u6d89\u53ca\u5230\u7684\u8868\u8fdb\u884c\u52a0\u9501\uff0c\u4ee5\u9632\u6b62\u5176\u4ed6\u4e8b\u52a1\u3002\u5982\u679c\u6ca1\u6709\u6267\u884c rollback\uff0c\u8fd9\u4e9b\u9501\u5c06\u4e00\u76f4\u4fdd\u6301\uff0c\u4ece\u800c\u5bfc\u81f4\u6b7b\u9501\u6216\u6027\u80fd\u95ee\u9898\u3002 \u7ed3\u675f\u4e8b\u52a1\u72b6\u6001\uff1a\u4e8b\u52a1\u72b6\u6001\u4f1a\u4e00\u76f4\u4fdd\u6301\uff0c\u76f4\u5230\u6267\u884c commit \u6216 rollback\u3002\u5982\u679c\u4e0d\u7ed3\u675f\u4e8b\u52a1\uff0c\u5927\u91cf\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\u4f1a\u963b\u585e\u6570\u636e\u5e93\u8d44\u6e90\uff0c\u5bfc\u81f4 idle in transaction \u7d2f\u79ef\uff0c\u4ece\u800c\u964d\u4f4e\u6027\u80fd\u3002 \u56e0\u6b64\uff0c\u65e0\u8bba\u4e8b\u52a1\u662f\u5426\u6210\u529f\uff0c\u90fd\u5e94\u53ca\u65f6\u6267\u884c [&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-7849","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7849","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=7849"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7849\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}