{"id":5365,"date":"2020-07-29T23:47:47","date_gmt":"2020-07-29T15:47:47","guid":{"rendered":"http:\/\/39.97.231.10\/?p=5365"},"modified":"2020-07-29T23:47:47","modified_gmt":"2020-07-29T15:47:47","slug":"mysql-innodb-%e6%9c%aa%e4%bd%bf%e7%94%a8%e7%b4%a2%e5%bc%95%e5%af%bc%e8%87%b4%e8%a1%8c%e9%94%81%e8%bd%ac%e8%a1%a8%e9%94%81","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=5365","title":{"rendered":"MySQL InnoDB \u672a\u4f7f\u7528\u7d22\u5f15\u5bfc\u81f4\u884c\u9501\u8f6c\u8868\u9501"},"content":{"rendered":"<div class=\\\"blog_title\\\">\n<h2><span style=\\\"color: #000000; font-size: 1rem;\\\">MySQL InnoDB\u662fMySQL\u4e2d\u4f7f\u7528\u6700\u5e7f\u6cdb\u7684\u4e00\u79cd\u5b58\u50a8\u5f15\u64ce\uff0c\u652f\u6301\u4e8b\u52a1\uff0c\u652f\u6301\u8868\u7ea7\u9501\uff0c\u53e6\u5916\u8fd8\u5b9e\u73b0\u4e86\u884c\u7ea7\u9501\uff0c\u652f\u6301\u66f4\u597d\u7684\u5e76\u53d1\u5199\u64cd\u4f5c\u3002InnoDB\u884c\u7ea7\u9501\u662f\u901a\u8fc7\u7ed9\u7d22\u5f15\u4e0a\u7684\u7d22\u5f15\u9879\u52a0\u9501\u6765\u5b9e\u73b0\u7684\uff0c\u8fd9\u5c31\u5bfc\u81f4\u53ea\u6709\u901a\u8fc7\u7d22\u5f15\u6761\u4ef6\u68c0\u7d22\u6570\u636e\uff0cInnoDB\u624d\u4f1a\u4f7f\u7528\u884c\u7ea7\u9501\uff0c\u5426\u5219InnoDB\u5c06\u4f7f\u7528\u8868\u7ea7\u9501\u3002\u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u4f8b\u5b50\u6765\u9a8c\u8bc1\u5728\u672a\u4f7f\u7528\u7d22\u5f15\u7684\u60c5\u51b5\u4e0b\uff0c\u884c\u9501\u8f6c\u6210\u4e86\u8868\u9501\uff0c\u6848\u4f8b\u4f7f\u7528\u7684\u7248\u672c\u4e3aMySQL 5.7.19\u3002<\/span><\/h2>\n<\/div>\n<div class=\\\"blog_content\\\">\n<div class=\\\"blog_detail\\\">\n<div><\/div>\n<div><b>1\u3001\u8868\u7ed3\u6784\uff1a<\/b><\/div>\n<div><\/div>\n<div>\u8868tb\u4e2d\u53ea\u6709\u4e24\u4e2a\u5b57\u6bb5\uff0cid\u548cname\uff0c\u4e24\u4e2a\u5b57\u6bb5\u4e0a\u90fd\u6ca1\u6709\u7d22\u5f15\uff0c\u8868\u4e2d\u4e5f\u53ea\u67095\u6761\u6570\u636e\uff0c\u5982\u4e0b\uff1a<\/div>\n<div>\n<div># \u8868\u7ed3\u6784<\/div>\n<div>CREATE TABLE `tb` (<\/div>\n<div>\u00a0\u00a0`id` int(11) DEFAULT NULL,<\/div>\n<div>\u00a0\u00a0`name` varchar(50) DEFAULT NULL<\/div>\n<div>) ENGINE=InnoDB DEFAULT CHARSET=utf8;<\/div>\n<div><\/div>\n<div># \u8868\u4e2d\u6570\u636e<\/div>\n<div>mysql&gt; select * from tb;<\/div>\n<div>+&#8212;&#8212;+&#8212;&#8212;+<\/div>\n<div>| id\u00a0\u00a0\u00a0| name |<\/div>\n<div>+&#8212;&#8212;+&#8212;&#8212;+<\/div>\n<div>|\u00a0\u00a0\u00a0\u00a01 | 1\u00a0\u00a0\u00a0\u00a0|<\/div>\n<div>|\u00a0\u00a0\u00a0\u00a02 | 2\u00a0\u00a0\u00a0\u00a0|<\/div>\n<div>|\u00a0\u00a0\u00a0\u00a03 | 3\u00a0\u00a0\u00a0\u00a0|<\/div>\n<div>|\u00a0\u00a0\u00a0\u00a04 | 4\u00a0\u00a0\u00a0\u00a0|<\/div>\n<div>|\u00a0\u00a0\u00a0\u00a05 | 5\u00a0\u00a0\u00a0\u00a0|<\/div>\n<div>+&#8212;&#8212;+&#8212;&#8212;+<\/div>\n<div>5 rows in set (0.00 sec)<\/div>\n<\/div>\n<div><\/div>\n<div><b>2\u3001\u672a\u4f7f\u7528\u7d22\u5f15\u5bfc\u81f4\u884c\u9501\u8f6c\u6210\u8868\u9501<\/b><\/div>\n<div><\/div>\n<div>\u542f\u52a8\u4e24\u4e2a\u8fde\u63a5\uff0c\u5206\u522b\u4e3asession1\u548csession2\uff0csession1\u66f4\u65b0id\u4e3a1\u7684\u8bb0\u5f55\uff0csession2\u66f4\u65b0id\u4e3a2\u7684\u8bb0\u5f55\uff0c\u4e24\u4e2asession\u66f4\u65b0\u7684\u6570\u636e\u6ca1\u6709\u4ea4\u96c6\u3002\u6267\u884c\u60c5\u51b5\u5982\u4e0b\uff1a<\/div>\n<div>\n<table>\n<colgroup>\n<col \/>\n<col \/>\n<col \/><\/colgroup>\n<tbody>\n<tr>\n<td>\n<div>session1<\/div>\n<\/td>\n<td>\n<div>session2<\/div>\n<\/td>\n<td>\n<div>\u5907\u6ce8<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div>begin;<\/div>\n<\/td>\n<td>\n<div>begin;<\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div>select * from tb where id=1 for update;<\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><\/div>\n<\/td>\n<td>\n<div>select * from tb where id=2 for update;<\/div>\n<\/td>\n<td>\n<div>session2\u963b\u585e<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div>commit;<\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><\/div>\n<\/td>\n<td>\n<div>commit;<\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div>\u53d1\u73b0session2\u88absession1\u963b\u585e\uff0c\u53ea\u6709\u5f53session1\u63d0\u4ea4\u6216\u8005\u56de\u6eda\u4e4b\u540e\uff0csession2\u624d\u80fd\u8fd4\u56de\uff0csession1\u4e0esession2\u66f4\u65b0\u7684\u6570\u636e\u5e76\u6ca1\u6709\u4ea4\u96c6\uff0c\u663e\u7136\u884c\u9501\u5347\u7ea7\u6210\u4e86\u8868\u9501\u3002<\/div>\n<\/div>\n<div><\/div>\n<div><b>3\u3001\u52a0\u4e0a\u7d22\u5f15\uff0c\u518d\u6b21\u6267\u884c<\/b><\/div>\n<div><\/div>\n<div>\u7ed9\u8868tb\u52a0\u4e0a\u7d22\u5f15\uff0c\u518d\u6267\u884c\u4e00\u6b21\uff0c\u770b\u770bsession2\u8fd8\u4f1a\u4e0d\u4f1a\u963b\u585e\u3002<\/div>\n<div><\/div>\n<div>alter table tb add index idx_id(id);<\/div>\n<table>\n<colgroup>\n<col \/>\n<col \/>\n<col \/><\/colgroup>\n<tbody>\n<tr>\n<td>\n<div>session1<\/div>\n<\/td>\n<td>\n<div>session2<\/div>\n<\/td>\n<td>\n<div>\u5907\u6ce8<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div>begin;<\/div>\n<\/td>\n<td>\n<div>begin;<\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div>select * from tb where id=1 for update;<\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><\/div>\n<\/td>\n<td>\n<div>select * from tb where id=2 for update;<\/div>\n<\/td>\n<td>\n<div>session2\u6267\u884c\u6b63\u5e38\uff0c\u4e0d\u518d\u963b\u585e\u3002<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div>commit;<\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<div><\/div>\n<\/td>\n<td>\n<div>commit;<\/div>\n<\/td>\n<td>\n<div><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div>session2\u6267\u884c\u4e0d\u518d\u88ab\u963b\u585e\uff0c\u663e\u7136\u5728id\u5b57\u6bb5\u52a0\u4e86\u7d22\u5f15\u4e4b\u540e\uff0c\u7531\u4e8esession1\u548csession2\u66f4\u65b0\u7684\u6570\u636e\u6ca1\u6709\u4ea4\u96c6\uff0c\u884c\u7ea7\u9501\u80fd\u591f\u5e76\u884c\u66f4\u65b0\u6570\u636e\uff0csession2\u4e0d\u518d\u963b\u585e\u3002<\/div>\n<div><\/div>\n<div>MySQL InnoDB \u7684\u8fd9\u4e00\u7279\u6027\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u5e94\u5f53\u7279\u522b\u6ce8\u610f\uff0c\u907f\u514d\u7531\u4e8e\u672a\u4f7f\u7528\u7d22\u5f15\uff0c\u884c\u7ea7\u9501\u5347\u7ea7\u4e3a\u8868\u7ea7\u9501\uff0c\u5bfc\u81f4\u5e76\u53d1\u5ea6\u964d\u4f4e\uff0cSQL\u6267\u884c\u963b\u585e\uff0c\u5f71\u54cd\u6b63\u5e38\u4e1a\u52a1\u3002<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>MySQL InnoDB\u662fMySQL\u4e2d\u4f7f\u7528\u6700\u5e7f\u6cdb\u7684\u4e00\u79cd\u5b58\u50a8\u5f15\u64ce\uff0c\u652f\u6301\u4e8b\u52a1\uff0c\u652f\u6301\u8868\u7ea7\u9501\uff0c\u53e6\u5916\u8fd8\u5b9e\u73b0\u4e86\u884c\u7ea7\u9501\uff0c\u652f\u6301 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=5365\"> <span class=\"screen-reader-text\">MySQL InnoDB \u672a\u4f7f\u7528\u7d22\u5f15\u5bfc\u81f4\u884c\u9501\u8f6c\u8868\u9501<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[90,88],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"MySQL InnoDB\u662fMySQL\u4e2d\u4f7f\u7528\u6700\u5e7f\u6cdb\u7684\u4e00\u79cd\u5b58\u50a8\u5f15\u64ce\uff0c\u652f\u6301\u4e8b\u52a1\uff0c\u652f\u6301\u8868\u7ea7\u9501\uff0c\u53e6\u5916\u8fd8\u5b9e\u73b0\u4e86\u884c\u7ea7\u9501\uff0c\u652f\u6301&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5365"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5365"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5365\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5365"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}