InnoDB: Reloading a table that was evicted while empty caused an AUTO_INCREMENT value to be reset. (Bug #21454472, Bug #77743),但是并没有解决数据库重启后空表的auto_increment被重置的场景
一、场景重现:[root@Kenyon ~]# mysql test Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.27-log Source distribution Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create table tbl_kenyon(id int auto_increment primary key,vname varchar(32)) auto_increment 1000 engine innodb; Query OK, 0 rows affected (0.16 sec) mysql> create table tbl_kenyon2(id int auto_increment primary key,vname varchar(32)) auto_increment 1000 engine innodb; Query OK, 0 rows affected (0.04 sec) mysql> insert into tbl_kenyon (vname) values('Just test'); Query OK, 1 row affected (0.03 sec) mysql> show create table tbl_kenyon \G *************************** 1. row *************************** Table: tbl_kenyon Create Table: CREATE TABLE `tbl_kenyon` ( `id` int(11) NOT NULL AUTO_INCREMENT, `vname` varchar(32) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8 1 row in set (0.00 sec) mysql> show create table tbl_kenyon2 \G *************************** 1. row *************************** Table: tbl_kenyon2 Create Table: CREATE TABLE `tbl_kenyon2` ( `id` int(11) NOT NULL AUTO_INCREMENT, `vname` varchar(32) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8 1 row in set (0.00 sec)--重启数据库后,可以看到auto_increment变化了
mysql> show create table tbl_kenyon\G *************************** 1. row *************************** Table: tbl_kenyon Create Table: CREATE TABLE `tbl_kenyon` ( `id` int(11) NOT NULL AUTO_INCREMENT, `vname` varchar(32) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8 1 row in set (0.00 sec) mysql> show create table tbl_kenyon2\G *************************** 1. row *************************** Table: tbl_kenyon2 Create Table: CREATE TABLE `tbl_kenyon2` ( `id` int(11) NOT NULL AUTO_INCREMENT, `vname` varchar(32) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 1 row in set (0.00 sec)
1.对自增值有要求的场景存在风险
2.与历史数据合并时可能存在主键冲突
四、参考:
1.http://bugs.mysql.com/bug.php?id=78491
2.https://bugs.mysql.com/bug.php?id=77743