自动增长变量,测试后的疑问

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是如何计算出来的?

参与1

0同行回答

“答”则兼济天下,请您为题主分忧!

提问者

nanjing_2013
系统架构师北京卓望

相关问题

相关资料

相关文章

问题状态

  • 发布时间:2016-01-29
  • 关注会员:1 人
  • 问题浏览:1568
  • X社区推广