create table ai(i bigint(20) not null auto_increment,
primary key(i)) engine=innodb default charset=gbk;
mysql> show variables like 'auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 1 |
| auto_increment_offset | 1 |
+--------------------------+-------+
2 rows in set (0.01 sec)
mysql> insert into ai values(null),(null),(null);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from ai;
+---+
| i |
+---+
| 1 |
| 2 |
| 3 |
-----------
mysql> set auto_increment_increment=10;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 10 |
| auto_increment_offset | 1 |
+--------------------------+--
mysql> insert into ai values(null),(null),(null);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from ai;
+----+
| i |
+----+
| 1 |
| 2 |
| 3 |
| 11 |
| 21 |
| 31 |
------------
修改auto_increment_offset 的值。
mysql> set auto_increment_offset=5;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'auto_inc%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 10 |
| auto_increment_offset | 5 |
+--------------------------+-----
mysql> insert into ai values(null),(null),(null);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from ai;
+----+
| i |
+----+
| 1 |
| 2 |
| 3 |
| 11 |
| 21 |
| 31 |
| 45 |
| 55 |
| 65 |
------------------
疑问:11,45是如何计算出来的?