我通过alter命令手动更改了某个表的auto_increment值,但是第二天auto_increment种子值又恢复为旧值。
手动更改值(6000000000)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2017-02-28 18:48:41 |
+---------------------+
1 row in set (0.00 sec)
mysql> show create table fav_tab;
+-----------+-----------------------------------------------------------------------------------------------------------
| Table | Create Table
+-----------+-----------------------------------------------------------------------------------------------------------
| fav_shows | CREATE TABLE `fav_tab` (
`FAV_tab_ID` int(11) NOT NULL AUTO_INCREMENT,
`USER_ID` bigint(20) unsigned NOT NULL,
`SERIES_ID` varchar(50) DEFAULT NULL,
`Creation_dt` datetime DEFAULT NULL,
PRIMARY KEY (`FAV_tab_ID`),
KEY `USER_ID` (`USER_ID`),
KEY `IDX_SeriesID` (`SERIES_ID`),
CONSTRAINT `FK_fav_tab_user` FOREIGN KEY (`USER_ID`) REFERENCES `user` (`USER_ID`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6000000000 DEFAULT CHARSET=latin1 |
+-----------+-----------------------------------------------------------------------------------------------------------
1 row in set (0.00 sec)
次日价值自动更改(207458739)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2017-03-01 11:23:26 |
+---------------------+
1 row in set (0.00 sec)
mysql> show create table fav_tab;
+-----------+-------------------------------------------------------------------------------------------------
| Table | Create Table
+-----------+-------------------------------------------------------------------------------------------------
| fav_shows | CREATE TABLE `fav_tab` (
`FAV_tab_ID` int(11) NOT NULL AUTO_INCREMENT,
`USER_ID` bigint(20) unsigned NOT NULL,
`SERIES_ID` varchar(50) DEFAULT NULL,
`Creation_dt` datetime DEFAULT NULL,
PRIMARY KEY (`FAV_tab_ID`),
KEY `USER_ID` (`USER_ID`),
KEY `IDX_SeriesID` (`SERIES_ID`),
CONSTRAINT `FK_fav_tab_user` FOREIGN KEY (`USER_ID`) REFERENCES `user` (`USER_ID`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=207458739 DEFAULT CHARSET=latin1 |
+-----------+-------------------------------------------------------------------------------------------------
1 row in set (0.00 sec)
请帮助我理解,为什么会发生这种情况以及我们如何解决它?
答案 0 :(得分:1)
对于InnoDB表,这是预期和记录的行为,请参阅
http://dev.mysql.com/doc/refman/5.5/en/innodb-auto-increment-handling.html:
InnoDB使用内存中的自动递增计数器,只要服务器 运行。当服务器停止并重新启动时,InnoDB会重新初始化 第一个INSERT到表的每个表的计数器,如 如前所述。
服务器重启也会取消AUTO_INCREMENT = N的效果 您可以在CREATE TABLE和ALTER TABLE语句中使用table选项 使用InnoDB表来设置初始计数器值或更改 当前计数器值。