{"id":306334,"date":"2024-01-18T09:16:04","date_gmt":"2024-01-18T01:16:04","guid":{"rendered":"https:\/\/www.idc.net\/help\/306334\/"},"modified":"2024-01-18T09:16:04","modified_gmt":"2024-01-18T01:16:04","slug":"mysql-%e4%b8%8d%e5%90%8c%e9%9a%94%e7%a6%bb%e7%ba%a7%e5%88%ab%ef%bc%8c%e9%83%bd%e4%bd%bf%e7%94%a8%e4%ba%86%e4%bb%80%e4%b9%88%e9%94%81%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/306334\/","title":{"rendered":"MySQL \u4e0d\u540c\u9694\u79bb\u7ea7\u522b\uff0c\u90fd\u4f7f\u7528\u4e86\u4ec0\u4e48\u9501\uff1f"},"content":{"rendered":"<\/p>\n<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u6811\u54e5\u3002<\/p>\n<p>\u5982\u679c\u67e5\u8be2\u6216\u66f4\u65b0\u65f6\u7684\u6570\u636e\u7279\u522b\u591a\uff0c\u662f\u5426\u4ece\u884c\u9501\u4f1a\u5347\u7ea7\u4e3a\u8868\u9501\uff1f<\/p>\n<p>\u6b64\u5916\uff0c\u8fd8\u6709\u670b\u53cb\u7559\u8a00\u8bf4\u5230\uff1a\u4e0d\u540c\u7684\u9694\u79bb\u7ea7\u522b\u53ef\u80fd\u4f1a\u7528\u4e0d\u540c\u7684\u9501\uff0c\u53ef\u4ee5\u7ed3\u5408\u9694\u79bb\u7ea7\u522b\u6765\u804a\u804a\u3002\u5176\u5b9e\u4e0a\u9762\u867d\u7136\u662f\u4e24\u4e2a\u95ee\u9898\uff0c\u4f46\u5982\u679c\u4f60\u628a\u4e0d\u540c\u9694\u79bb\u7ea7\u522b\u4e0b\u7684\u52a0\u9501\u95ee\u9898\u641e\u6e05\u695a\u4e86\uff0c\u90a3\u4e48\u7b2c\u4e00\u4e2a\u95ee\u9898\u81ea\u7136\u4e5f\u6e05\u695a\u4e86\u3002<\/p>\n<p>\u4eca\u5929\uff0c\u5c31\u8ba9\u6211\u5e26\u7740\u5927\u5bb6\u6765\u804a\u804a\u4e0d\u540c\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u90fd\u4f1a\u4f7f\u7528\u4ec0\u4e48\u9501\uff01<\/p>\n<p style=\"text-align:center\">\n<p style=\"text-align: center\">\u6587\u7ae0\u601d\u7ef4\u5bfc\u56fe<\/p>\n<h4>\u8bf4\u900f MySQL \u9501\u673a\u5236<\/h4>\n<p>\u5728\u6df1\u5165\u63a2\u8ba8\u4e0d\u540c\u9694\u79bb\u7ea7\u522b\u7684\u9501\u5185\u5bb9\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5148\u56de\u987e\u4e00\u4e0b\u5173\u4e8e MySQL \u9501\u7684\u672c\u8d28\u4ee5\u53ca\u4e00\u4e9b\u57fa\u7840\u5185\u5bb9\uff0c\u8fd9\u6837\u6709\u5229\u4e8e\u6211\u4eec\u540e\u7eed\u7684\u7406\u89e3\u3002<\/p>\n<p>\u5bf9\u4e8e MySQL \u6765\u8bf4\uff0c\u5982\u679c\u53ea\u652f\u6301\u4e32\u884c\u8bbf\u95ee\u7684\u8bdd\uff0c\u90a3\u4e48\u5176\u6548\u7387\u4f1a\u975e\u5e38\u4f4e\u3002\u56e0\u6b64\uff0c\u4e3a\u4e86\u63d0\u9ad8\u6570\u636e\u5e93\u7684\u8fd0\u884c\u6548\u7387\uff0cMySQL \u9700\u8981\u652f\u6301\u5e76\u53d1\u8bbf\u95ee\u3002<\/p>\n<p>\u800c\u5728\u5e76\u53d1\u8bbf\u95ee\u7684\u60c5\u51b5\u4e0b\uff0c\u4f1a\u53d1\u751f\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u4f8b\u5982\uff1a\u810f\u8bfb\u3001\u4e0d\u53ef\u91cd\u590d\u8bfb\u3001\u5e7b\u8bfb\u7b49\u95ee\u9898\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff0c\u5c31\u51fa\u73b0\u4e86\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u3002<\/p>\n<p>\u672c\u8d28\u4e0a\uff0c\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u5c31\u662f\u4e3a\u4e86\u89e3\u51b3\u5e76\u53d1\u8bbf\u95ee\u4e0b\u7684\u6570\u636e\u4e00\u81f4\u6027\u95ee\u9898\u7684\u3002\u4e0d\u540c\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\uff0c\u89e3\u51b3\u4e86\u4e0d\u540c\u7a0b\u5ea6\u7684\u6570\u636e\u4e00\u81f4\u6027\u3002<\/p>\n<p>\u800c\u6211\u4eec\u6240\u8bf4\u7684\u5168\u5c40\u9501\u3001\u8868\u9501\u3001\u884c\u7ea7\u9501\u7b49\u7b49\uff0c\u5176\u5b9e\u90fd\u662f\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u7684\u5177\u4f53\u5b9e\u73b0\u3002\u800c MVCC\u3001\u610f\u5411\u9501\uff0c\u5219\u662f\u4e00\u4e9b\u5c40\u90e8\u7684\u6027\u80fd\u4f18\u5316\u3002<\/p>\n<p>\u4e0a\u9762\u8fd9\u6bb5\u8bdd\uff0c\u57fa\u672c\u4e0a\u5c31\u662f\u5bf9 MySQL \u9501\u673a\u5236\u5f88\u900f\u5f7b\u7684\u7406\u89e3\u3002\u5f53\u6211\u4eec\u61c2\u4e86\u8fd9\u4e9b\u6982\u5ff5\u4e4b\u95f4\u7684\u5173\u7cfb\u4e4b\u540e\uff0c\u6211\u4eec\u624d\u80fd\u66f4\u52a0\u6e05\u6670\u5730\u7406\u89e3\u77e5\u8bc6\u70b9\u3002<\/p>\n<h4>\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b<\/h4>\n<p>\u76f8\u4fe1\u5927\u5bb6\u90fd\u77e5\u9053\uff0cMySQL \u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u6709\u5982\u4e0b 4 \u4e2a\uff0c\u5206\u522b\u662f\uff1a<\/p>\n<ul>\n<li>\u8bfb\u672a\u63d0\u4ea4<\/li>\n<li>\u8bfb\u5df2\u63d0\u4ea4\uff08READ COMMITTED)<\/li>\n<li>\u53ef\u91cd\u590d\u8bfb\uff08REPEATABLE READ\uff09<\/li>\n<li>\u4e32\u884c\u5316<\/li>\n<\/ul>\n<p>\u8bfb\u672a\u63d0\u4ea4\uff0c\u53ef\u4ee5\u8bfb\u53d6\u5230\u5176\u4ed6\u4e8b\u52a1\u8fd8\u6ca1\u63d0\u4ea4\u7684\u6570\u636e\u3002&nbsp;\u5728\u8fd9\u4e2a\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u7531\u4e8e\u53ef\u4ee5\u8bfb\u53d6\u5230\u672a\u63d0\u4ea4\u7684\u503c\uff0c\u56e0\u6b64\u4f1a\u4ea7\u751f\u300c\u810f\u8bfb\u300d\u95ee\u9898\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff1aA \u4e8b\u52a1\u66f4\u65b0\u4e86 price \u4e3a 30\uff0c\u4f46\u8fd8\u672a\u63d0\u4ea4\u3002\u6b64\u65f6 B \u4e8b\u52a1\u8bfb\u53d6\u5230\u4e86 price \u4e3a 30\uff0c\u4f46\u540e\u7eed A \u4e8b\u52a1\u56de\u6eda\u4e86\uff0c\u90a3\u4e48 B \u4e8b\u52a1\u8bfb\u53d6\u5230\u7684 price \u5c31\u662f\u9519\u7684\uff08\u810f\u7684\uff09\u3002<\/p>\n<p>\u8bfb\u5df2\u63d0\u4ea4\uff0c\u53ea\u80fd\u8bfb\u5230\u5176\u4ed6\u4e8b\u52a1\u5df2\u7ecf\u63d0\u4ea4\u7684\u6570\u636e\u3002&nbsp;\u8fd9\u4e2a\u9694\u79bb\u7ea7\u522b\u89e3\u51b3\u4e86\u810f\u8bfb\u7684\u95ee\u9898\uff0c\u4e0d\u4f1a\u8bfb\u5230\u672a\u63d0\u4ea4\u7684\u503c\uff0c\u4f46\u662f\u5374\u4f1a\u4ea7\u751f\u300c\u4e0d\u53ef\u91cd\u590d\u8bfb\u300d\u95ee\u9898\u3002\u300c\u4e0d\u53ef\u91cd\u590d\u8bfb\u300d\u6307\u7684\u662f\u5728\u540c\u4e00\u4e2a\u4e8b\u52a1\u8303\u56f4\u5185\uff0c\u524d\u540e\u4e24\u6b21\u8bfb\u53d6\u5230\u7684\u6570\u636e\u4e0d\u4e00\u6837\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff1aA \u4e8b\u52a1\u7b2c 1 \u6b21\u8bfb\u53d6\u4e86 price \u4e3a 10\u3002<\/p>\n<p>\u968f\u540e B \u4e8b\u52a1\u5c06 price \u66f4\u65b0\u4e3a 20\uff0c\u63a5\u7740 A \u4e8b\u52a1\u518d\u6b21\u8bfb\u53d6 price \u4e3a 30\u3002A \u4e8b\u52a1\u524d\u540e\u4e24\u6b21\u8bfb\u53d6\u5230\u7684\u6570\u636e\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u8fd9\u5c31\u662f\u4e0d\u53ef\u91cd\u590d\u8bfb\u3002<\/p>\n<p>\u601d\u8003\u9898\uff1aMySQL \u8bfb\u5df2\u63d0\u4ea4\u53ef\u4ee5\u89e3\u51b3\u810f\u8bfb\u95ee\u9898\uff0c\u90a3\u5b83\u5177\u4f53\u662f\u5982\u4f55\u89e3\u51b3\u7684\uff1f<\/p>\n<p>\u53ef\u91cd\u590d\u8bfb\uff0c\u6307\u7684\u662f\u540c\u4e00\u4e8b\u52a1\u8303\u56f4\u5185\u8bfb\u53d6\u5230\u7684\u6570\u636e\u662f\u4e00\u81f4\u7684\u3002&nbsp;\u8fd9\u4e2a\u9694\u79bb\u7ea7\u522b\u89e3\u51b3\u4e86\u300c\u4e0d\u53ef\u91cd\u590d\u8bfb\u300d\u7684\u95ee\u9898\uff0c\u53ea\u8981\u662f\u5728\u540c\u4e00\u4e8b\u52a1\u8303\u56f4\u5185\uff0c\u90a3\u4e48\u8bfb\u53d6\u5230\u7684\u6570\u636e\u5c31\u662f\u4e00\u6837\u7684\u3002\u5bf9\u4e8e MySQL Innodb \u6765\u8bf4\uff0c\u5176\u5b9e\u901a\u8fc7 MVCC \u6765\u5b9e\u73b0\u7684\u3002\u4f46\u300c\u53ef\u91cd\u590d\u8bfb\u300d\u9694\u79bb\u7ea7\u522b\u4f1a\u4ea7\u751f\u5e7b\u8bfb\u95ee\u9898\uff0c\u5373\u5bf9\u4e8e\u67d0\u4e2a\u8303\u56f4\u7684\u6570\u636e\u8bfb\u53d6\uff0c\u524d\u540e\u4e24\u6b21\u53ef\u80fd\u8bfb\u53d6\u5230\u4e0d\u540c\u7684\u7ed3\u679c\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff1a\u6570\u636e\u5e93\u4e2d\u6709 price \u4e3a 1\u30013\u30015 \u4e09\u4e2a\u5546\u54c1\uff0c\u6b64\u65f6 A \u4e8b\u52a1\u67e5\u8be2 price &lt; 10 \u7684\u5546\u54c1\uff0c\u67e5\u8be2\u5230\u4e86 3 \u4e2a\u5546\u54c1\u3002\u968f\u540e B \u4e8b\u52a1\u63d2\u5165\u4e86\u4e00\u6761 price \u4e3a 7 \u7684\u5546\u54c1\u3002\u63a5\u7740 A \u4e8b\u52a1\u7ee7\u7eed\u67e5\u8be2 price &lt; 10 \u7684\u5546\u54c1\uff0c\u8fd9\u6b21\u5374\u67e5\u8be2\u5230\u4e86 4 \u4e2a\u5546\u54c1\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5230\u300c\u5e7b\u8bfb\u300d\u4e0e\u300c\u4e0d\u53ef\u91cd\u590d\u8bfb\u300d\u662f\u6709\u4e9b\u7c7b\u4f3c\u7684\uff0c\u53ea\u662f\u300c\u4e0d\u53ef\u91cd\u590d\u8bfb\u300d\u66f4\u591a\u6307\u7684\u662f\u67d0\u4e00\u6761\u8bb0\u5f55\uff0c\u800c\u300c\u5e7b\u8bfb\u300d\u6307\u7684\u5219\u662f\u67d0\u4e2a\u8303\u56f4\u6570\u636e\u3002\u5bf9\u4e8e MySQL Innodb \u6765\u8bf4\uff0c\u5176\u901a\u8fc7\u884c\u7ea7\u9501\u7ea7\u522b\u7684 Gap Lock \u89e3\u51b3\u4e86\u5e7b\u8bfb\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4e32\u884c\u5316\uff0c\u6307\u7684\u662f\u6240\u6709\u4e8b\u52a1\u4e32\u884c\u6267\u884c\u3002&nbsp;\u8fd9\u4e2a\u5c31\u6700\u7b80\u5355\u4e86\uff0c\u4e0d\u7528\u53bb\u7ade\u4e89\uff0c\u4e00\u4e2a\u4e2a\u53bb\u6267\u884c\uff0c\u4f46\u662f\u6548\u7387\u4e5f\u662f\u6700\u4f4e\u7684\u3002<\/p>\n<h4>MySQL \u9501\u7c7b\u578b<\/h4>\n<p>\u5728 MySQL \u4e2d\u6709\u5168\u5c40\u9501\u3001\u8868\u7ea7\u9501\u3001\u884c\u7ea7\u9501\u4e09\u79cd\u7c7b\u578b\uff0c\u5176\u4e2d\u6bd4\u8f83\u5173\u952e\u7684\u662f\u8868\u7ea7\u9501\u76d2\u884c\u7ea7\u9501\u3002<\/p>\n<p>\u5bf9\u4e8e\u8868\u7ea7\u9501\u800c\u8a00\uff0c\u5176\u53c8\u5206\u4e3a\u8868\u9501\u3001\u5143\u6570\u636e\u9501\u3001\u610f\u5411\u9501\u4e09\u79cd\u3002\u5bf9\u4e8e\u5143\u6570\u636e\u9501\u800c\u8a00\uff0c\u57fa\u672c\u4e0a\u90fd\u662f\u6570\u636e\u5e93\u81ea\u884c\u64cd\u4f5c\uff0c\u6211\u4eec\u65e0\u987b\u5173\u5fc3\u3002\u5728 Innodb \u5b58\u50a8\u5b58\u50a8\u5f15\u64ce\u4e2d\uff0c\u8868\u9501\u4e5f\u7528\u5f97\u6bd4\u8f83\u5c11\u3002<\/p>\n<p>\u5bf9\u4e8e\u884c\u7ea7\u9501\u800c\u8a00\uff0c\u5176\u53c8\u8bb0\u5f55\u9501\u3001\u95f4\u9699\u9501\u3001Next-Key \u9501\u3002\u8bb0\u5f55\u9501\u5c31\u662f\u67d0\u4e2a\u7d22\u5f15\u8bb0\u5f55\u7684\u9501\uff0c\u95f4\u9699\u9501\u5c31\u662f\u4e24\u4e2a\u7d22\u5f15\u8bb0\u5f55\u4e4b\u95f4\u7684\u7a7a\u9699\u9501\uff0cNext-Key \u5219\u662f\u524d\u9762\u4e24\u8005\u7684\u7ed3\u5408\u3002<\/p>\n<p>\u5728 Innodb \u5b58\u50a8\u5f15\u64ce\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u7684\u547d\u4ee4\u6765\u67e5\u8be2\u9501\u7684\u60c5\u51b5\u3002<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u5f00\u542f\u9501\u7684\u65e5\u5fd7<br><span style=\"margin: 0px;padding: 0px\">set<\/span> global innodb_status_output_locks<span style=\"margin: 0px;padding: 0px\">=<\/span><span style=\"margin: 0px;padding: 0px\">on<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span> <br><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u67e5\u770binnodb\u5f15\u64ce\u7684\u4fe1\u606f<span style=\"margin: 0px;padding: 0px\">(<\/span>\u5305\u542b\u9501\u7684\u4fe1\u606f<span style=\"margin: 0px;padding: 0px\">)<\/span><br>show engine innodb status\\G<span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u67e5\u8be2\u7ed3\u679c\u4e00\u822c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p style=\"text-align:center\">\n<p>\u4e0a\u9762\u51e0\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u9501\uff0c\u5176\u5404\u81ea\u7684\u5173\u952e\u5b57\u4e3a\uff1a<\/p>\n<ul>\n<li>\u8868\u7ea7\u7684\u610f\u5411\u6392\u5b83\u9501\uff08IX\uff09\uff1alock mode IX\u3002<\/li>\n<li>\u8868\u7ea7\u7684\u63d2\u5165\u610f\u5411\u9501\uff08LOCK_INSERT_INTENTION\uff09: lock_mode X locks gap before rec insert intention<\/li>\n<li>\u884c\u7ea7\u7684\u8bb0\u5f55\u9501\uff08LOCK_REC_NOT_GAP\uff09: lock_mode X locks rec but not gap<\/li>\n<li>\u884c\u7ea7\u7684\u95f4\u9699\u9501\uff08LOCK_GAP\uff09: lock_mode X locks gap before rec<\/li>\n<li>\u884c\u7ea7\u7684 Next-key \u9501\uff08LOCK_ORNIDARY\uff09: lock_mode X<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684\u547d\u4ee4\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u77e5\u9053\u4e0d\u540c\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u4f7f\u7528\u4e86\u54ea\u4e9b\u9501\u4e86\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4e00\u4e2a\u4e2a\u6765\u770b\u770b\uff1a\u4e0d\u540c\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\uff0c\u90fd\u4f7f\u7528\u4e86\u54ea\u4e9b\u9501\u6765\u5b9e\u73b0\u3002<\/p>\n<h4>\u8bfb\u672a\u63d0\u4ea4<\/h4>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a price_test \u8868\u5e76\u63d2\u5165\u4e00\u4e9b\u6d4b\u8bd5\u6570\u636e\u3002<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u521b\u5efa price_test \u8868<br><span style=\"margin: 0px;padding: 0px\">CREATE<\/span> <span style=\"margin: 0px;padding: 0px\">TABLE<\/span> `test`.`price_test` <span style=\"margin: 0px;padding: 0px\">(<\/span><br>  `id` <span style=\"margin: 0px;padding: 0px\">BIGINT<\/span><span style=\"margin: 0px;padding: 0px\">(<\/span><span style=\"margin: 0px;padding: 0px\">64<\/span><span style=\"margin: 0px;padding: 0px\">)<\/span> <span style=\"margin: 0px;padding: 0px\">NOT<\/span> <span style=\"margin: 0px;padding: 0px\">NULL<\/span> AUTO_INCREMENT<span style=\"margin: 0px;padding: 0px\">,<\/span><br>  `name` <span style=\"margin: 0px;padding: 0px\">varchar<\/span><span style=\"margin: 0px;padding: 0px\">(<\/span><span style=\"margin: 0px;padding: 0px\">32<\/span><span style=\"margin: 0px;padding: 0px\">)<\/span> <span style=\"margin: 0px;padding: 0px\">not<\/span> <span style=\"margin: 0px;padding: 0px\">null<\/span><span style=\"margin: 0px;padding: 0px\">,<\/span><br>  `price` <span style=\"margin: 0px;padding: 0px\">INTEGER<\/span><span style=\"margin: 0px;padding: 0px\">(<\/span><span style=\"margin: 0px;padding: 0px\">4<\/span><span style=\"margin: 0px;padding: 0px\">)<\/span> <span style=\"margin: 0px;padding: 0px\">NULL<\/span><span style=\"margin: 0px;padding: 0px\">,<\/span><br>  PRIMARY KEY <span style=\"margin: 0px;padding: 0px\">(<\/span>`id`<span style=\"margin: 0px;padding: 0px\">)<\/span><span style=\"margin: 0px;padding: 0px\">)<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u63d2\u5165\u6d4b\u8bd5\u6570\u636e<br><span style=\"margin: 0px;padding: 0px\">INSERT<\/span> <span style=\"margin: 0px;padding: 0px\">INTO<\/span> price_test<span style=\"margin: 0px;padding: 0px\">(<\/span>name<span style=\"margin: 0px;padding: 0px\">,<\/span>price<span style=\"margin: 0px;padding: 0px\">)<\/span> <span style=\"margin: 0px;padding: 0px\">values<\/span><span style=\"margin: 0px;padding: 0px\">(<\/span><span style=\"margin: 0px;padding: 0px\">'apple'<\/span><span style=\"margin: 0px;padding: 0px\">,<\/span> <span style=\"margin: 0px;padding: 0px\">10<\/span><span style=\"margin: 0px;padding: 0px\">)<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u63a5\u7740\uff0c\u6211\u4eec\u6253\u5f00\u4e24\u4e2a\u547d\u4ee4\u884c\u7a97\u53e3\uff0c\u5e76\u4e14\u90fd\u4fee\u6539\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u4e3a\u300c\u8bfb\u672a\u63d0\u4ea4\u300d\u3002<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u8bbe\u7f6e\u9694\u79bb\u7ea7\u522b<br><span style=\"margin: 0px;padding: 0px\">SET<\/span> session TRANSACTION ISOLATION LEVEL READ UNCOMMITTED<span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u67e5\u770b\u9694\u79bb\u7ea7\u522b<br><span style=\"margin: 0px;padding: 0px\">select<\/span> @@transaction_isolation<span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u63a5\u7740\uff0c\u4e8b\u52a1 A \u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff0c\u67e5\u8be2\u51fa id \u4e3a 1 \u8bb0\u5f55\u7684 price \u503c\u3002<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u6267\u884c\u547d\u4ee4<br>beign<span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">select<\/span> <span style=\"margin: 0px;padding: 0px\">*<\/span> <span style=\"margin: 0px;padding: 0px\">from<\/span> price_test <span style=\"margin: 0px;padding: 0px\">where<\/span> id <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">1<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u6267\u884c\u7ed3\u679c<br><span style=\"margin: 0px;padding: 0px\">+----+-------+-------+<\/span><br><span style=\"margin: 0px;padding: 0px\">|<\/span> id <span style=\"margin: 0px;padding: 0px\">|<\/span> name  <span style=\"margin: 0px;padding: 0px\">|<\/span> price <span style=\"margin: 0px;padding: 0px\">|<\/span><br><span style=\"margin: 0px;padding: 0px\">+----+-------+-------+<\/span><br><span style=\"margin: 0px;padding: 0px\">|<\/span>  <span style=\"margin: 0px;padding: 0px\">1<\/span> <span style=\"margin: 0px;padding: 0px\">|<\/span> apple <span style=\"margin: 0px;padding: 0px\">|<\/span>    <span style=\"margin: 0px;padding: 0px\">10<\/span> <span style=\"margin: 0px;padding: 0px\">|<\/span><br><span style=\"margin: 0px;padding: 0px\">+----+-------+-------+<\/span><br><span style=\"margin: 0px;padding: 0px\">1<\/span> row <span style=\"margin: 0px;padding: 0px\">in<\/span> <span style=\"margin: 0px;padding: 0px\">set<\/span> <span style=\"margin: 0px;padding: 0px\">(<\/span><span style=\"margin: 0px;padding: 0px\">0.00<\/span> sec<span style=\"margin: 0px;padding: 0px\">)<\/span><\/pre>\n<p>\u63a5\u7740\uff0c\u4e8b\u52a1 B \u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff0c\u4fee\u6539 price \u4e3a 20\u3002<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">update<\/span> price_test <span style=\"margin: 0px;padding: 0px\">set<\/span> price <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">20<\/span> <span style=\"margin: 0px;padding: 0px\">where<\/span> id <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">1<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u63a5\u7740\uff0c\u4e8b\u52a1 A \u518d\u6b21\u8bfb\u53d6 id \u4e3a 1 \u8bb0\u5f55\u7684 price \u503c\u3002<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">select<\/span> <span style=\"margin: 0px;padding: 0px\">*<\/span> <span style=\"margin: 0px;padding: 0px\">from<\/span> price_test <span style=\"margin: 0px;padding: 0px\">where<\/span> id <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">1<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u4ece\u4e0b\u56fe\u53ef\u4ee5\u770b\u5230\uff0c\u4e8b\u52a1 A \u8bfb\u53d6\u5230\u4e86\u4e8b\u52a1 B \u672a\u63d0\u4ea4\u7684\u6570\u636e\uff0c\u8fd9\u5176\u5b9e\u5c31\u662f\u810f\u8bfb\u4e86\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u4ece\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u4e00\u4e9b\u7ed3\u8bba\uff1a\u5728\u300c\u8bfb\u672a\u63d0\u4ea4\u300d\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u8bfb\u5199\u662f\u53ef\u4ee5\u540c\u65f6\u8fdb\u884c\u7684\uff0c\u4e0d\u4f1a\u963b\u585e\u3002<\/p>\n<p>\u770b\u5230\u8fd9\u91cc\uff0c\u6211\u7a81\u7136\u60f3\u5230\u4e86\u4e00\u4e2a\u95ee\u9898\uff1a\u90a3\u4e48\u5199\u5199\u662f\u5426\u4f1a\u963b\u585e\u963b\u585e\u5462\uff1f<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u7ee7\u7eed\u505a\u4e00\u4e2a\u6d4b\u8bd5\uff1a\u4e8b\u52a1 A \u548c \u4e8b\u52a1 B \u540c\u65f6\u5bf9 id \u4e3a 1 \u7684\u8bb0\u5f55\u8fdb\u884c\u66f4\u65b0\uff0c\u770b\u770b\u662f\u5426\u80fd\u591f\u66f4\u65b0\u6210\u529f\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u6211\u5148\u7528\u5982\u4e0b\u547d\u4ee4\u5728\u4e8b\u52a1 A\uff08\u4e0a\u8fb9\u7684\u7a97\u53e3\uff09\u6267\u884c\uff0c\u5c06 price \u4fee\u6539\u4e3a 15\u3002<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">update<\/span> price_test <span style=\"margin: 0px;padding: 0px\">set<\/span> price <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">15<\/span> <span style=\"margin: 0px;padding: 0px\">where<\/span> id <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">1<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u7ed3\u679c\u6267\u884c\u6210\u529f\u4e86\uff0c\u4f46\u6b64\u65f6\u4e8b\u52a1 A \u8fd8\u672a\u63d0\u4ea4\u3002<\/p>\n<p>\u63a5\u7740\uff0c\u6211\u5148\u7528\u5982\u4e0b\u547d\u4ee4\u5728\u4e8b\u52a1 B\uff08\u4e0b\u8fb9\u7684\u7a97\u53e3\uff09\u6267\u884c\uff0c\u5c06 price \u4fee\u6539\u4e3a 20\u3002<\/p>\n<p>\u4ece\u56fe\u4e2d\u53ef\u4ee5\u770b\u5230\uff0c\u4e8b\u52a1 B \u963b\u585e\u5361\u4f4f\u4e86\u3002<\/p>\n<p>\u4ece\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\u7ed3\u8bba\uff1a\u5728\u300c\u8bfb\u672a\u63d0\u4ea4\u300d\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u5199\u5199\u4e0d\u53ef\u4ee5\u540c\u65f6\u8fdb\u884c\u7684\uff0c\u4f1a\u963b\u585e\u3002<\/p>\n<p>\u6b64\u65f6\uff0c\u6211\u4eec\u901a\u8fc7\u67e5\u770b\u9501\u4fe1\u606f\u53ef\u4ee5\u770b\u5230\uff0c\u5176\u662f\u52a0\u4e0a\u4e00\u4e2a\u884c\u7ea7\u522b\u7684\u8bb0\u5f55\u9501\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u5f53\u6211\u4f7f\u7528 rollback \u547d\u4ee4\u56de\u6eda\u4e8b\u52a1 A \u4e4b\u540e\uff0c\u4e8b\u52a1 B \u7acb\u523b\u5c31\u6267\u884c\u4e86\uff0c\u5e76\u4e14\u4e8b\u52a1 A \u8fd8\u8bfb\u53d6\u5230\u4e86\u4e8b\u52a1 B \u8bbe\u7f6e\u7684\u503c\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u6709\u4e9b\u5c0f\u4f19\u4f34\u4f1a\u8bf4\uff1a\u5982\u679c\u6307\u5b9a\u4e86\u975e\u7d22\u5f15\u7684\u5217\u4f5c\u4e3a\u67e5\u8be2\u6761\u4ef6\uff0c\u662f\u5426\u4f1a\u89e6\u53d1\u95f4\u9699\u9501\u5462\uff1f<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u6d4b\u8bd5\u4e00\u4e0b\u3002<\/p>\n<p>\u6211\u4eec\u5f80 price_test \u8868\u518d\u63d2\u5165\u4e00\u6761\u6570\u636e\uff0c\u6b64\u65f6\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u63a5\u7740\uff0c\u6211\u4eec\u5728\u4e8b\u52a1 A \u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff0c\u67e5\u8be2 price &gt; 15 \u7684\u8bb0\u5f55\u3002<\/p>\n<pre>mysql<span style=\"margin: 0px;padding: 0px\">&gt;<\/span> <span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br>Query OK<span style=\"margin: 0px;padding: 0px\">,<\/span> <span style=\"margin: 0px;padding: 0px\">0<\/span> rows affected <span style=\"margin: 0px;padding: 0px\">(<\/span><span style=\"margin: 0px;padding: 0px\">0.00<\/span> sec<span style=\"margin: 0px;padding: 0px\">)<\/span><br>mysql<span style=\"margin: 0px;padding: 0px\">&gt;<\/span> <span style=\"margin: 0px;padding: 0px\">select<\/span> <span style=\"margin: 0px;padding: 0px\">*<\/span> <span style=\"margin: 0px;padding: 0px\">from<\/span> price_test <span style=\"margin: 0px;padding: 0px\">where<\/span> price <span style=\"margin: 0px;padding: 0px\">&gt;<\/span> <span style=\"margin: 0px;padding: 0px\">15<\/span> for <span style=\"margin: 0px;padding: 0px\">update<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">+----+--------+-------+<\/span><br><span style=\"margin: 0px;padding: 0px\">|<\/span> id <span style=\"margin: 0px;padding: 0px\">|<\/span> name   <span style=\"margin: 0px;padding: 0px\">|<\/span> price <span style=\"margin: 0px;padding: 0px\">|<\/span><br><span style=\"margin: 0px;padding: 0px\">+----+--------+-------+<\/span><br><span style=\"margin: 0px;padding: 0px\">|<\/span>  <span style=\"margin: 0px;padding: 0px\">2<\/span> <span style=\"margin: 0px;padding: 0px\">|<\/span> orange <span style=\"margin: 0px;padding: 0px\">|<\/span>    <span style=\"margin: 0px;padding: 0px\">30<\/span> <span style=\"margin: 0px;padding: 0px\">|<\/span><br><span style=\"margin: 0px;padding: 0px\">+----+--------+-------+<\/span><br><span style=\"margin: 0px;padding: 0px\">1<\/span> row <span style=\"margin: 0px;padding: 0px\">in<\/span> <span style=\"margin: 0px;padding: 0px\">set<\/span> <span style=\"margin: 0px;padding: 0px\">(<\/span><span style=\"margin: 0px;padding: 0px\">0.00<\/span> sec<span style=\"margin: 0px;padding: 0px\">)<\/span><\/pre>\n<p>\u63a5\u7740\uff0c\u6211\u4eec\u5728\u4e8b\u52a1 B \u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff0c\u67e5\u8be2 price &gt; 5 \u7684\u8bb0\u5f55\u3002<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">select<\/span> <span style=\"margin: 0px;padding: 0px\">*<\/span> <span style=\"margin: 0px;padding: 0px\">from<\/span> price_test <span style=\"margin: 0px;padding: 0px\">where<\/span> price <span style=\"margin: 0px;padding: 0px\">&gt;<\/span> <span style=\"margin: 0px;padding: 0px\">5<\/span> for <span style=\"margin: 0px;padding: 0px\">update<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u4ece\u5982\u4e0b\u7ed3\u679c\u53ef\u4ee5\u770b\u5230\uff0c\u4e8b\u52a1 B \u963b\u585e\u4f4f\u4e86\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u6b64\u65f6\u6211\u4eec\u5728\u4e8b\u52a1 A \u67e5\u770b\u9501\u7684\u60c5\u51b5\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0cMySQL \u53ea\u662f\u52a0\u4e0a\u4e86\u4e00\u4e2a\u8bb0\u5f55\u9501\uff0c\u5e76\u6ca1\u6709\u52a0\u95f4\u9699\u9501\u3002<\/p>\n<p>\u6700\u540e\u6211\u4eec\u603b\u7ed3\u4e00\u4e0b\uff1a\u5728\u300c\u8bfb\u672a\u63d0\u4ea4\u300d\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u8bfb\u5199\u64cd\u4f5c\u53ef\u4ee5\u540c\u65f6\u8fdb\u884c\uff0c\u4f46\u5199\u5199\u64cd\u4f5c\u65e0\u6cd5\u540c\u65f6\u8fdb\u884c\u3002\u4e0e\u6b64\u540c\u65f6\uff0c\u8be5\u9694\u79bb\u7ea7\u522b\u4e0b\u53ea\u4f1a\u4f7f\u7528\u884c\u7ea7\u522b\u7684\u8bb0\u5f55\u9501\uff0c\u5e76\u4e0d\u4f1a\u7528\u95f4\u9699\u9501\u3002<\/p>\n<h4>\u8bfb\u5df2\u63d0\u4ea4<\/h4>\n<p>\u5728\u300c\u8bfb\u5df2\u63d0\u4ea4\u300d\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u6211\u4eec\u6309\u4e4b\u524d\u7684\u65b9\u5f0f\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8bbe\u7f6e\u4e00\u4e0b\u9694\u79bb\u7ea7\u522b\u4e3a\u300c\u8bfb\u5df2\u63d0\u4ea4\u300d\u3002<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u8bbe\u7f6e\u9694\u79bb\u7ea7\u522b<br><span style=\"margin: 0px;padding: 0px\">SET<\/span> session TRANSACTION ISOLATION LEVEL READ COMMITTED<span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u67e5\u770b\u9694\u79bb\u7ea7\u522b<br><span style=\"margin: 0px;padding: 0px\">select<\/span> @@transaction_isolation<span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u63a5\u7740\uff0c\u6211\u4eec\u6d4b\u8bd5\u540c\u65f6\u5bf9 id \u4e3a 1 \u7684\u6570\u636e\u8fdb\u884c\u66f4\u65b0\uff0c\u770b\u770b\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002<\/p>\n<p>\u4e8b\u52a1 A \u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">update<\/span> price_test <span style=\"margin: 0px;padding: 0px\">set<\/span> price <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">15<\/span> <span style=\"margin: 0px;padding: 0px\">where<\/span> id <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">1<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u4e8b\u52a1 B \u6267\u884c\u5982\u4e0b\u547d\u4ee4<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">update<\/span> price_test <span style=\"margin: 0px;padding: 0px\">set<\/span> price <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">20<\/span> <span style=\"margin: 0px;padding: 0px\">where<\/span> id <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">1<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u4e8b\u52a1 B \u963b\u585e\u4e86\u3002\u67e5\u770b\u4e0b\u9501\u4fe1\u606f\uff0c\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5176\u9501\u662f\u4e00\u4e2a\u884c\u7ea7\u522b\u7684\u8bb0\u5f55\u9501\uff0c\u7ed3\u679c\u548c\u300c\u8bfb\u672a\u63d0\u4ea4\u300d\u7684\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u7ee7\u7eed\u770b\u770b\u8303\u56f4\u7684\u67e5\u8be2\u662f\u5426\u4f1a\u89e6\u53d1\u95f4\u9699\u9501\u3002<\/p>\n<p>\u4e8b\u52a1 A \u6267\u884c\uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">select<\/span> <span style=\"margin: 0px;padding: 0px\">*<\/span> <span style=\"margin: 0px;padding: 0px\">from<\/span> price_test <span style=\"margin: 0px;padding: 0px\">where<\/span> price <span style=\"margin: 0px;padding: 0px\">&gt;<\/span> <span style=\"margin: 0px;padding: 0px\">5<\/span> for <span style=\"margin: 0px;padding: 0px\">update<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u4e8b\u52a1 B \u6267\u884c\uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">select<\/span> <span style=\"margin: 0px;padding: 0px\">*<\/span> <span style=\"margin: 0px;padding: 0px\">from<\/span> price_test <span style=\"margin: 0px;padding: 0px\">where<\/span> price <span style=\"margin: 0px;padding: 0px\">&gt;<\/span> <span style=\"margin: 0px;padding: 0px\">15<\/span> for <span style=\"margin: 0px;padding: 0px\">update<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u4e8b\u52a1 B \u4f1a\u963b\u585e\uff0c\u67e5\u770b\u9501\u4fe1\u606f\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u8fd8\u662f\u53ea\u6709\u4e00\u4e2a\u884c\u7ea7\u522b\u7684\u8bb0\u5f55\u9501\uff0c\u5e76\u6ca1\u6709\u95f4\u9699\u9501\u3002<\/p>\n<p>\u770b\u5230\u8fd9\u91cc\uff0c\u4f60\u4f1a\u53d1\u73b0\u300c\u8bfb\u5df2\u63d0\u4ea4\u300d\u548c\u300c\u8bfb\u672a\u63d0\u4ea4\u300d\u975e\u5e38\u76f8\u4f3c\u3002\u90a3\u4e48\u5b83\u4eec\u5177\u4f53\u6709\u5565\u533a\u522b\u5462\uff1f<\/p>\n<p>\u5176\u5b9e\u4ed6\u4eec\u7684\u6700\u5927\u533a\u522b\uff0c\u5c31\u662f\u300c\u8bfb\u5df2\u63d0\u4ea4\u300d\u89e3\u51b3\u4e86\u810f\u8bfb\u7684\u95ee\u9898\u3002<\/p>\n<h4>\u53ef\u91cd\u590d\u8bfb<\/h4>\n<p>\u5728\u300c\u8bfb\u5df2\u63d0\u4ea4\u300d\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u6211\u4eec\u6309\u4e4b\u524d\u7684\u65b9\u5f0f\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8bbe\u7f6e\u4e00\u4e0b\u9694\u79bb\u7ea7\u522b\u4e3a\u300c\u8bfb\u5df2\u63d0\u4ea4\u300d\u3002<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u8bbe\u7f6e\u9694\u79bb\u7ea7\u522b<br><span style=\"margin: 0px;padding: 0px\">SET<\/span> session TRANSACTION ISOLATION LEVEL REPEATABLE READ<span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">\/\/<\/span> \u67e5\u770b\u9694\u79bb\u7ea7\u522b<br><span style=\"margin: 0px;padding: 0px\">select<\/span> @@transaction_isolation<span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u63a5\u7740\uff0c\u6211\u4eec\u6d4b\u8bd5\u540c\u65f6\u5bf9 id \u4e3a 1 \u7684\u6570\u636e\u8fdb\u884c\u66f4\u65b0\uff0c\u770b\u770b\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002<\/p>\n<p>\u4e8b\u52a1 A \u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">update<\/span> price_test <span style=\"margin: 0px;padding: 0px\">set<\/span> price <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">15<\/span> <span style=\"margin: 0px;padding: 0px\">where<\/span> id <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">1<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u4e8b\u52a1 B \u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">update<\/span> price_test <span style=\"margin: 0px;padding: 0px\">set<\/span> price <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">20<\/span> <span style=\"margin: 0px;padding: 0px\">where<\/span> id <span style=\"margin: 0px;padding: 0px\">=<\/span> <span style=\"margin: 0px;padding: 0px\">1<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u4e8b\u52a1 B \u963b\u585e\u4e86\u3002\u67e5\u770b\u4e0b\u9501\u4fe1\u606f\uff0c\u6beb\u65e0\u7591\u95ee\uff0c\u5176\u5b9e\u8fd9\u91cc\u8fd8\u662f\u53ea\u4f1a\u6709\u95f4\u9699\u9501\uff0c\u56e0\u4e3a\u6307\u5b9a\u4e86\u7d22\u5f15\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u7ee7\u7eed\u770b\u770b\u8303\u56f4\u7684\u67e5\u8be2\u662f\u5426\u4f1a\u89e6\u53d1\u95f4\u9699\u9501\u3002<\/p>\n<p>\u4e8b\u52a1 A \u6267\u884c\uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">select<\/span> <span style=\"margin: 0px;padding: 0px\">*<\/span> <span style=\"margin: 0px;padding: 0px\">from<\/span> price_test <span style=\"margin: 0px;padding: 0px\">where<\/span> price <span style=\"margin: 0px;padding: 0px\">&gt;<\/span> <span style=\"margin: 0px;padding: 0px\">5<\/span> for <span style=\"margin: 0px;padding: 0px\">update<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u4e8b\u52a1 B \u6267\u884c\uff1a<\/p>\n<pre><span style=\"margin: 0px;padding: 0px\">begin<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><br><span style=\"margin: 0px;padding: 0px\">select<\/span> <span style=\"margin: 0px;padding: 0px\">*<\/span> <span style=\"margin: 0px;padding: 0px\">from<\/span> price_test <span style=\"margin: 0px;padding: 0px\">where<\/span> price <span style=\"margin: 0px;padding: 0px\">&gt;<\/span> <span style=\"margin: 0px;padding: 0px\">15<\/span> for <span style=\"margin: 0px;padding: 0px\">update<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/pre>\n<p>\u4e8b\u52a1 B \u4f1a\u963b\u585e\uff0c\u67e5\u770b\u9501\u4fe1\u606f\u5982\u4e0b\u56fe\u6240\u793a\u3002<\/p>\n<p style=\"text-align:center\">\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5728\u8fd9\u91cc\u5c31\u53d8\u6210\u4e86 Next-Key \u9501\uff0c\u5c31\u662f\u8bb0\u5f55\u9501\u548c\u95f4\u9699\u9501\u7ed3\u5408\u4f53\u3002<\/p>\n<p>\u603b\u7ed3\u4e00\u4e0b\uff1a\u5728\u300c\u53ef\u91cd\u590d\u8bfb\u300d\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u4f7f\u7528\u4e86\u8bb0\u5f55\u9501\u3001\u95f4\u9699\u9501\u3001Next-Key \u9501\u4e09\u79cd\u7c7b\u578b\u7684\u9501\u3002<\/p>\n<p>\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u6211\u4eec\u524d\u9762\u8bf4\u8fc7\uff1a\u53ef\u91cd\u590d\u8bfb\u5b58\u5728\u5e7b\u8bfb\u7684\u95ee\u9898\uff0c\u4f46\u5b9e\u9645\u4e0a\u5728 MySQL \u4e2d\uff0c\u56e0\u4e3a\u5176\u4f7f\u7528\u4e86\u95f4\u9699\u9501\uff0c\u6240\u4ee5\u5728\u300c\u53ef\u91cd\u590d\u8bfb\u300d\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u5176\u5b9e\u4e0d\u5b58\u5728\u5e7b\u8bfb\u95ee\u9898\u3002\u56e0\u6b64\uff0cMySQL \u5c06\u300c\u53ef\u91cd\u590d\u8bfb\u300d\u4f5c\u4e3a\u4e86\u5176\u9ed8\u8ba4\u7684\u9694\u79bb\u7ea7\u522b\u3002<\/p>\n<h4>\u603b\u7ed3<\/h4>\n<p>\u770b\u5230\u8fd9\u91cc\uff0c\u6211\u60f3\u6211\u4eec\u53ef\u4ee5\u5bf9\u6587\u7ae0\u5f00\u5934\u63d0\u51fa\u7684\u95ee\u9898\u505a\u4e2a\u89e3\u7b54\u4e86\uff1aMySQL \u4e0d\u540c\u9694\u79bb\u7ea7\u522b\uff0c\u90fd\u4f7f\u7528\u4e86\u4ec0\u4e48\u6837\u7684\u9501\uff1f<\/p>\n<p>\u5bf9\u4e8e\u4efb\u4f55\u9694\u79bb\u7ea7\u522b\uff0c\u8868\u7ea7\u522b\u7684\u8868\u9501\u3001\u5143\u6570\u636e\u9501\u3001\u610f\u5411\u9501\u90fd\u662f\u4f1a\u4f7f\u7528\u7684\uff0c\u4f46\u5bf9\u4e8e\u884c\u7ea7\u522b\u7684\u9501\u5219\u4f1a\u6709\u4e9b\u8bb8\u5dee\u522b\u3002<\/p>\n<p>\u5728\u300c\u8bfb\u672a\u63d0\u4ea4\u300d\u548c\u300c\u8bfb\u5df2\u63d0\u4ea4\u300d\u9694\u79bb\u7ea7\u522b\u4e0b\uff0c\u90fd\u53ea\u4f1a\u4f7f\u7528\u8bb0\u5f55\u9501\uff0c\u4e0d\u4f1a\u7528\u95f4\u9699\u9501\uff0c\u5f53\u7136\u4e5f\u4e0d\u4f1a\u6709 Next-Key \u9501\u4e86\u3002<\/p>\n<p>\u800c\u5bf9\u4e8e\u300c\u53ef\u91cd\u590d\u8bfb\u300d\u9694\u79bb\u7ea7\u522b\u6765\u8bf4\uff0c\u4f1a\u4f7f\u7528\u8bb0\u5f55\u9501\u3001\u95f4\u9699\u9501\u548c Next-Key \u9501\u3002<\/p>\n<p>\u4eca\u5929\u6211\u4eec\u662f\u4ece\u9694\u79bb\u7ea7\u522b\u8fd9\u4e2a\u89d2\u5ea6\u6765\u770b\u9501\u7684\u5e94\u7528\uff0c\u4f46\u4ec0\u4e48\u65f6\u5019\u4f1a\u7528\u4e0a\u8bb0\u5f55\u9501\uff1f\u4ec0\u4e48\u65f6\u5019\u4f1a\u7528\u4e0a\u95f4\u9699\u9501\uff1f\u540e\u9762\u6709\u673a\u4f1a\uff0c\u6211\u4eec\u5c06\u804a\u804a\u8fd9\u90e8\u5206\u7684\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u6811\u54e5\u3002 \u5982\u679c\u67e5\u8be2\u6216\u66f4\u65b0\u65f6\u7684\u6570\u636e\u7279\u522b\u591a\uff0c\u662f\u5426\u4ece\u884c\u9501\u4f1a\u5347\u7ea7\u4e3a\u8868\u9501\uff1f \u6b64\u5916\uff0c\u8fd8\u6709\u670b\u53cb\u7559\u8a00\u8bf4\u5230\uff1a\u4e0d\u540c\u7684\u9694\u79bb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":306335,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7038],"tags":[],"class_list":["post-306334","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/306334","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=306334"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/306334\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/306335"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=306334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=306334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=306334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}