【发布时间】:2016-01-21 01:03:34
【问题描述】:
我看到一个奇怪的行为,我的自动增量列号仅以 2 而不是 1 的步长增加。所以我最终的行 ID 为 1、3、5、7。我使用 MySQL 5.6 + InnoDB 作为引擎。知道为什么会出现这种奇怪现象吗?
mysql> select version();
+-----------------+
| version() |
+-----------------+
| 5.6.20-68.0-log |
+-----------------+
1 row in set (0.00 sec)
mysql> show create table temp_table;
| superset_version | CREATE TABLE `temp_table` (
`_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'comm1',
`name` varchar(100) NOT NULL COMMENT 'comm2',
`start_time` bigint(20) NOT NULL COMMENT 'comm3',
`updated_at` bigint(20) NOT NULL COMMENT 'comm4',
`status` varchar(50) NOT NULL COMMENT 'comm5',
PRIMARY KEY (`_id`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8 |
请注意,插入将 _id 列增加了 2。
mysql> insert into superset_version(name, start_time, updated_at, status) value("TEMP ROW", -1, -1, "erro");
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select * from superset_version order by _id desc limit 3;
+-----+----------+------------+------------+--------+
| _id | name | start_time | updated_at | status |
+-----+----------+------------+------------+--------+
| 33 | TEMP ROW | -1 | -1 | erro |
| 31 | TEMP ROW | -1 | -1 | erro |
| 29 | TEMP ROW | -1 | -1 | erro |
+-----+----------+------------+------------+--------+
3 rows in set (0.00 sec)
【问题讨论】:
-
“1 个警告” ...
mysql> SHOW WARNINGS; -
糟糕,我之前在插入中交换了列并粘贴了该版本,但后来我意识到并更正了插入语句,但忘记粘贴正确的输出。请放心,上述声明不会发出任何警告。