{"id":5393,"date":"2020-07-30T00:14:38","date_gmt":"2020-07-29T16:14:38","guid":{"rendered":"http:\/\/39.97.231.10\/?p=5393"},"modified":"2020-07-30T00:14:38","modified_gmt":"2020-07-29T16:14:38","slug":"mysql-bug-replace-into-%e8%af%ad%e5%8f%a5%e5%af%bc%e8%87%b4%e4%b8%bb%e4%bb%8e%e5%88%87%e6%8d%a2%e5%90%8e%e4%b8%bb%e9%94%ae%e5%86%b2%e7%aa%81","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=5393","title":{"rendered":"MySQL bug replace into \u8bed\u53e5\u5bfc\u81f4\u4e3b\u4ece\u5207\u6362\u540e\u4e3b\u952e\u51b2\u7a81"},"content":{"rendered":"<div>\n<div>\n\u4e00\u3001\u80cc\u666f\n<\/div>\n<\/div>\n<div>\n<div>\n\u751f\u4ea7\u73af\u5883\u9047\u5230\u4e00\u4e2a MySQL \u5199\u5165\u62a5\u9519\u7684\u95ee\u9898\uff0c\u4e1a\u52a1\u5199\u5165\u6570\u636e\u65f6\u62a5\u4e3b\u952e\u51b2\u7a81\u3002\u7ecf\u8fc7\u8c03\u67e5\uff0c\u8fd9\u5957 MySQL \u96c6\u7fa4\u7248\u672c\u4e3a Percona 5.7.19\uff0c\u5728\u62a5\u4e3b\u952e\u51b2\u7a81\u524d\uff0c\u505a\u8fc7\u4e3b\u4ece\u5207\u6362\uff0c\u62a5\u4e3b\u952e\u51b2\u7a81\u7684SQL\u8bed\u53e5\u4e3a replace into\uff0c\u8868\u7684\u4e3b\u952e\u662f\u81ea\u589e\u5217\uff0c\u8c03\u67e5\u8be5\u8868\u7684 auto_increment\uff0c\u53d1\u73b0\u4e00\u4e2a\u5f88\u5947\u602a\u7684\u95ee\u9898\uff0c\u8be5\u8868\u7684 auto_increment \u7adf\u7136\u6bd4\u8868\u6570\u636e\u7684 max(id) \u8fd8\u5c0f\uff0c\u96be\u602a\u4f1a\u51fa\u73b0\u4e3b\u952e\u51b2\u7a81\u4e86\u3002<br \/>\n\u90a3\u4e48\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0 auto_increment \u6bd4 max(id) \u8fd8\u5c0f\uff1f\u641c\u7d22\u4e00\u4e0b\uff0c\u53d1\u73b0\u679c\u7136\u662f MySQL \u7684\u4e00\u4e2a Bug\uff0c\u89c1\u94fe\u63a5\uff1a<br \/>\n<a href=\\\"https:\/\/bugs.mysql.com\/bug.php?id=83030\\\">https:\/\/bugs.mysql.com\/bug.php?id=83030<\/a><br \/>\n\u7b80\u5355\u6765\u8bf4\uff0creplace into \u8bed\u53e5\u901a\u8fc7\u552f\u4e00\u952e\u76f8\u540c\u4fee\u6539\u8bb0\u5f55\u65f6\uff0c\u4e3b\u5e93\u4e0a\u8be5\u8868\u7684 auto_increment \u4f1a\u53d8\u5316\uff0c\u800c\u4ece\u5e93\u4e0a\u8be5\u8868\u7684 auto_increment \u503c\u4e0d\u53d8\u3002\u6240\u4ee5\u5728\u4ece\u5e93\u4e0a\u4f1a\u51fa\u73b0 auto_increment \u503c\u6bd4 max(id) \u8fd8\u5c0f\u7684\u60c5\u51b5\uff0c\u505a\u4e3b\u4ece\u5207\u6362\u4e4b\u540e\uff0c\u5199\u5165\u6570\u636e\uff0c\u5c31\u53ef\u80fd\u4f1a\u53d1\u751f\u4e3b\u952e\u51b2\u7a81\u3002<\/p>\n<h4>\u4e8c\u3001\u590d\u73b0\u65b9\u6cd5<\/h4>\n<p>\u53e6\u5916\u4e5f\u641c\u7d22\u5230\u4e00\u7bc7\u6587\u7ae0\uff0c\u63cf\u8ff0\u4e86\u540c\u6837\u7684 Bug \u548c \u590d\u73b0\u65b9\u6cd5\uff0c\u89c1\u94fe\u63a5\uff1a<br \/>\n<a href=\\\"https:\/\/developer.aliyun.com\/article\/57855\\\">https:\/\/developer.aliyun.com\/article\/57855<\/a><br \/>\n\u62f7\u8d1d\u4e0a\u8ff0\u94fe\u63a5\u539f\u6587\u5982\u4e0b\uff1a<\/p>\n<h5>2.1 \u590d\u73b0\u6761\u4ef6<\/h5>\n<ul>\n<li>MySQL 5.7<\/li>\n<li>ROW\u6a21\u5f0f<\/li>\n<\/ul>\n<p>\u8868\u7ed3\u6784\uff1a<\/p>\n<pre>CREATE TABLE `test` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `col_1` varchar(100) DEFAULT NULL,\n  `col_2` varchar(100) DEFAULT NULL,\n  `col_3` varchar(100) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `col_1` (`col_1`)\n) ENGINE=InnoDB  DEFAULT CHARSET=utf8\n<\/pre>\n<h5>2.2 \u590d\u73b0\u6b65\u9aa4<\/h5>\n<p>\u521d\u59cb\u5316\u6570\u636e\uff1a<\/p>\n<pre>mater:lc&gt; REPLACE INTO test (col_1,col_2,col_3) values(\\'a\\',\\'a\\',\\'a\\');\nQuery OK, 1 row affected (0.00 sec) --\u6ce8\u610f\uff0c\u8fd9\u91cc\u662f\u5f71\u54cd\u4e861\u6761\u8bb0\u5f55\nmaster:lc&gt; REPLACE INTO test (col_1,col_2,col_3) values(\\'b\\',\\'b\\',\\'b\\');\nQuery OK, 1 row affected (0.00 sec) --\u6ce8\u610f\uff0c\u8fd9\u91cc\u662f\u5f71\u54cd\u4e861\u6761\u8bb0\u5f55\nmaster:lc&gt; REPLACE INTO test (col_1,col_2,col_3) values(\\'c\\',\\'c\\',\\'c\\');\nQuery OK, 1 row affected (0.00 sec) --\u6ce8\u610f\uff0c\u8fd9\u91cc\u662f\u5f71\u54cd\u4e861\u6761\u8bb0\u5f55\n<\/pre>\n<p>\u67e5\u8be2\u4e3b\u5e93\u8868\u7ed3\u6784\uff0c\u53d1\u73b0 AUTO_INCREMENT=4\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre>master &gt; show create table test\n| test  | CREATE TABLE `test` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `col_1` varchar(100) DEFAULT NULL,\n  `col_2` varchar(100) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `col_1` (`col_1`)\n) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 |\n<\/pre>\n<p>\u67e5\u8be2\u4ece\u5e93\u8868\u7ed3\u6784\uff0c\u53d1\u73b0 AUTO_INCREMENT=4\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre>slave &gt; show create table test\n| test  | CREATE TABLE `test` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `col_1` varchar(100) DEFAULT NULL,\n  `col_2` varchar(100) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `col_1` (`col_1`)\n) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 |\n<\/pre>\n<p>\u4ee5\u4e0a\u90fd\u5f88\u6b63\u5e38\uff0c\u4e0b\u9762\u5c31\u662f\u89c1\u8bc1\u5947\u8ff9\u7684\u65f6\u523b\uff0c\u5728\u4e3b\u5e93\u6267\u884c\u4e0b\u9762\u7684SQL\uff1a<\/p>\n<pre>mater:lc&gt; REPLACE INTO test (col_1,col_2) values(\\'c\\',\\'cc\\');\nQuery OK, 2 rows affected (0.00 sec)  --\u6ce8\u610f\uff0c\u8fd9\u91cc\u662f\u5f71\u54cd\u4e86\u4e24\u6761\u8bb0\u5f55\n<\/pre>\n<p>\u7136\u540e\u518d\u770b\u4e3b\u3001\u4ece\u5e93\u8868\u7ed3\u6784\u7684 AUTO_INCREMENT \u503c\uff0c\u53d1\u73b0\u4e3b\u5e93 AUTO_INCREMENT=5\uff0c\u4ece\u5e93 AUTO_INCREMENT=4\uff0c\u4e3b\u4ece\u5e93\u6570\u636e\u5b8c\u5168\u4e00\u81f4\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre>mater:lc&gt; show create table test\n| test  | CREATE TABLE `test` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `col_1` varchar(100) DEFAULT NULL,\n  `col_2` varchar(100) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `col_1` (`col_1`)\n) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 |\nmaster:lc&gt; select * from test\n+----+-------+-------+\n| id | col_1 | col_2 |\n+----+-------+-------+\n|  1 | a     | a     |\n|  2 | b     | b     |\n|  4 | c     | cc    |\n+----+-------+-------+\n3 rows in set (0.00 sec)\nslave:lc&gt; show create table test\n| test  | CREATE TABLE `test` (\n  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `col_1` varchar(100) DEFAULT NULL,\n  `col_2` varchar(100) DEFAULT NULL,\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `col_1` (`col_1`)\n) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 |\nslave:lc&gt; select * from test\n+----+-------+-------+\n| id | col_1 | col_2 |\n+----+-------+-------+\n|  1 | a     | a     |\n|  2 | b     | b     |\n|  4 | c     | cc    |\n+----+-------+-------+\n3 rows in set (0.00 sec)\n<\/pre>\n<p>\u5728\u4e0d\u540c\u7684MySQL\u7248\u672c\u4e0a\u6d4b\u8bd5\u8be5 Bug\uff0c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>5.7.30 \u672a\u4fee\u590d<\/li>\n<li>8.0.20 \u5df2\u4fee\u590d<\/li>\n<\/ul>\n<p>\u8fd9\u4e2a Bug \u5f88\u5bb9\u6613\u590d\u73b0\uff0c\u5f88\u4e45\u4e4b\u524d\u5c31\u5df2\u7ecf\u88ab\u63d0\u51fa\u6765\uff0c\u76f4\u5230\u73b0\u5728\u90fd\u6ca1\u6709\u5728 5.7 \u7248\u672c\u8fdb\u884c\u4fee\u590d\u3002\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u80cc\u666f \u751f\u4ea7\u73af\u5883\u9047\u5230\u4e00\u4e2a MySQL \u5199\u5165\u62a5\u9519\u7684\u95ee\u9898\uff0c\u4e1a\u52a1\u5199\u5165\u6570\u636e\u65f6\u62a5\u4e3b\u952e\u51b2\u7a81\u3002\u7ecf\u8fc7\u8c03\u67e5\uff0c\u8fd9\u5957 MySQL  &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=5393\"> <span class=\"screen-reader-text\">MySQL bug replace into \u8bed\u53e5\u5bfc\u81f4\u4e3b\u4ece\u5207\u6362\u540e\u4e3b\u952e\u51b2\u7a81<\/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":"\u4e00\u3001\u80cc\u666f \u751f\u4ea7\u73af\u5883\u9047\u5230\u4e00\u4e2a MySQL \u5199\u5165\u62a5\u9519\u7684\u95ee\u9898\uff0c\u4e1a\u52a1\u5199\u5165\u6570\u636e\u65f6\u62a5\u4e3b\u952e\u51b2\u7a81\u3002\u7ecf\u8fc7\u8c03\u67e5\uff0c\u8fd9\u5957 MySQL &hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5393"}],"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=5393"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5393\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5393"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}