自动增量种子值在 RDS 上恢复为旧值

Auto Increment Seed Values get revert back to old value on RDS

我通过 alter 命令手动更改了一些 table 的 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)

请帮助我理解,为什么会发生这种情况以及我们如何解决它?

For InnoDB tables this is expected and documented behavior, see

http://dev.mysql.com/doc/refman/5.5/en/innodb-auto-increment-handling.html:

InnoDB uses the in-memory auto-increment counter as long as the server runs. When the server is stopped and restarted, InnoDB reinitializes the counter for each table for the first INSERT to the table, as described earlier.

A server restart also cancels the effect of the AUTO_INCREMENT = N table option in CREATE TABLE and ALTER TABLE statements, which you can use with InnoDB tables to set the initial counter value or alter the current counter value.