{"id":6303,"date":"2024-11-14T13:15:16","date_gmt":"2024-11-14T05:15:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6303\/"},"modified":"2024-11-14T13:15:16","modified_gmt":"2024-11-14T05:15:16","slug":"mysql-acid-%e8%a6%81%e7%82%b9","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6303\/","title":{"rendered":"MySQL ACID \u8981\u70b9"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/164\/172129961136496.jpg\" class=\"aligncenter\" title=\"MySQL ACID \u8981\u70b9\u63d2\u56fe\" alt=\"MySQL ACID \u8981\u70b9\u63d2\u56fe\" \/><\/p>\n<p>acid \u5c5e\u6027\u5728\u6570\u636e\u5e93\u7ba1\u7406\u4e2d\u81f3\u5173\u91cd\u8981\uff0c\u53ef\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u4e00\u81f4\u6027\u3002\u672c\u7b80\u77ed\u6307\u5357\u901a\u8fc7\u5173\u952e\u793a\u4f8b\u4ecb\u7ecd\u4e86  \u4e2d acid \u7684\u57fa\u7840\u77e5\u8bc6\u3002<\/p>\n<h3> \u539f\u5b50\u6027 <\/h3>\n<p>\u5c06\u4e8b\u52a1\u8bed\u53e5\u89c6\u4e3a\u4e00\u4e2a\u5355\u5143\uff0c\u786e\u4fdd\u6240\u6709\u6216\u90fd\u4e0d\u6267\u884c\u3002<\/p>\n<pre>start transaction;\ninsert into products (id, name) values (1, 'product a');\ninsert into products (id, name) values (2, 'product b');\ncommit;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u4e00\u81f4\u6027 <\/h3>\n<p>\u901a\u8fc7\u9075\u5b88\u9884\u5b9a\u4e49\u7684\u89c4\u5219\u6765\u786e\u4fdd\u6570\u636e\u5e93\u4e00\u81f4\u6027\u3002<\/p>\n<pre>start transaction;\nupdate products set stock = stock - 10 where id = 1;\nupdate products set stock = stock + 10 where id = 2;\ncommit;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u9694\u79bb <\/h3>\n<p>\u786e\u4fdd\u4ea4\u6613\u72ec\u7acb\u6267\u884c\u3002<\/p>\n<pre>set transaction isolation level read committed;\nstart transaction;\nselect * from products where id = 1;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3> \u8010\u7528\u6027 <\/h3>\n<p>\u786e\u4fdd\u5df2\u63d0\u4ea4\u7684\u4e8b\u52a1\u5728\u7cfb\u7edf\u5d29\u6e83\u540e\u4ecd\u7136\u5b58\u5728\u3002<\/p>\n<pre>START TRANSACTION;\nINSERT INTO sales (id, amount) VALUES (1, 500);\nCOMMIT;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2> \u5e38\u95ee\u95ee\u9898 <\/h2>\n<p><strong>\u4ec0\u4e48\u662f\u9178\u6027\uff1f<\/strong><\/p>\n<p>acid \u4ee3\u8868\u539f\u5b50\u6027\u3001\u4e00\u81f4\u6027\u3001\u9694\u79bb\u6027\u548c\u6301\u4e45\u6027\uff0c\u5bf9\u4e8e\u53ef\u9760\u7684\u6570\u636e\u5e93\u4e8b\u52a1\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48acid\u5728mysql\u4e2d\u5f88\u91cd\u8981\uff1f<\/strong><\/p>\n<p>acid \u5c5e\u6027\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u548c\u4e00\u81f4\u6027\uff0c\u5373\u4f7f\u5728\u6545\u969c\u671f\u95f4\u4e5f\u662f\u5982\u6b64\u3002<\/p>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u8c03\u6574acid\u4ee5\u83b7\u5f97\u66f4\u597d\u7684\u6027\u80fd\uff1f<\/strong><\/p>\n<p>\u662f\u7684\uff0c\u4fee\u6539 mysql \u914d\u7f6e\u6587\u4ef6\u8bbe\u7f6e\uff08my.cnf \u6216 my.ini\uff09\u53ef\u4ee5\u5728\u4fdd\u6301 acid \u5408\u89c4\u6027\u7684\u540c\u65f6\u4f18\u5316\u6027\u80fd\u3002<\/p>\n<p><strong>mysql \u4e2d\u54ea\u4e9b\u5b58\u50a8\u5f15\u64ce\u652f\u6301 acid\uff1f<\/strong><\/p>\n<p>innodb \u548c percona xtradb \u662f mysql \u4e2d\u652f\u6301 acid \u7684\u4e3b\u8981\u5b58\u50a8\u5f15\u64ce\u3002<\/p>\n<h2> \u7ed3\u8bba <\/h2>\n<p>acid \u5c5e\u6027\u5bf9\u4e8e\u6709\u6548\u7684 mysql \u6570\u636e\u5e93\u7ba1\u7406\u3001\u786e\u4fdd\u6570\u636e\u53ef\u9760\u6027\u548c\u5b8c\u6574\u6027\u81f3\u5173\u91cd\u8981\u3002\u6709\u5173\u8be6\u7ec6\u6307\u5357\uff0c\u8bf7\u9605\u8bfb mysql \u4e2d\u7684 acid \u6307\u5357\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL ACID \u8981\u70b9\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>acid \u5c5e\u6027\u5728\u6570\u636e\u5e93\u7ba1\u7406\u4e2d\u81f3\u5173\u91cd\u8981\uff0c\u53ef\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u4e00\u81f4\u6027\u3002\u672c\u7b80\u77ed\u6307\u5357\u901a\u8fc7\u5173\u952e\u793a\u4f8b\u4ecb\u7ecd\u4e86 \u4e2d acid \u7684\u57fa\u7840\u77e5\u8bc6\u3002 \u539f\u5b50\u6027 \u5c06\u4e8b\u52a1\u8bed\u53e5\u89c6\u4e3a\u4e00\u4e2a\u5355\u5143\uff0c\u786e\u4fdd\u6240\u6709\u6216\u90fd\u4e0d\u6267\u884c\u3002 start transaction; insert into products (id, name) values (1, &#8216;product a&#8217;); insert into products (id, name) values (2, &#8216;product b&#8217;); commit; \u767b\u5f55\u540e\u590d\u5236 \u4e00\u81f4\u6027 \u901a\u8fc7\u9075\u5b88\u9884\u5b9a\u4e49\u7684\u89c4\u5219\u6765\u786e\u4fdd\u6570\u636e\u5e93\u4e00\u81f4\u6027\u3002 start transaction; update products set stock = stock &#8211; 10 where id = 1; update products set stock = stock + 10 where id [&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-6303","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6303","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=6303"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6303\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}