{"id":200119,"date":"2025-05-06T10:22:18","date_gmt":"2025-05-06T02:22:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200119\/"},"modified":"2025-05-06T10:22:18","modified_gmt":"2025-05-06T02:22:18","slug":"mysql-acid-%e8%a6%81%e7%82%b9","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200119\/","title":{"rendered":"MySQL ACID \u8981\u70b9"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>MySQL ACID \u8981\u70b9<\/h1>\n<p>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240718\/17212907336698cfeda930e.jpg\" class=\"aligncenter\"><\/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 mysql \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<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<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<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<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>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aMySQL ACID \u8981\u70b9\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u5427\uff01<\/p>\n<p> \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664 <\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>MySQL ACID \u8981\u70b9 \u4e0d\u77e5&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200119","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200119"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200119\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}