MySQL自增长的bug?

实验环境:

mysql> status
--------------
mysql Ver 14.14 Distrib 5.7.14, for Linux (x86_64) using EditLine wrapper

……

mysql> show variables like 'auto_increment%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 1     |
| auto_increment_offset    | 1     |
+--------------------------+-------+
2 rows in set (0.03 sec)
auto_increment_offset:默认自增长起始点值;
auto_increment_increment:默认自增长增量值;

截图取材于标准MySQL5.7官方文档--没有盗版

mysql> create table t1(id int not null primary key auto_increment);
Query OK, 0 rows affected (0.21 sec)

mysql> insert into t1 values(null),(null),(null);
Query OK, 3 rows affected (0.06 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from t1;
+----+
| id |
+----+
|  1 |
|  2 |
|  3 |
+----+
3 rows in set (0.00 sec) 

 

1、修改自增长变量值

mysql> set @@auto_increment_offset=10;
Query OK, 0 rows affected (0.00 sec)

mysql> set @@auto_increment_increment=5;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like 'auto_increment%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 5     |
| auto_increment_offset    | 10    |
+--------------------------+-------+
2 rows in set (0.02 sec)

 通过变量的修改,现在的自增长起始值是10,增量是5

 

2、建表插值

mysql> create table t2(id int not null primary key auto_increment);
Query OK, 0 rows affected (0.11 sec)

mysql> insert into t2 values(null),(null),(null);
Query OK, 3 rows affected (0.04 sec)
Records: 3  Duplicates: 0  Warnings: 0

因为自增长起始值是10,增量是5;猜想结果值是10,15,20

 

3、查询结果

mysql> select * from t2;
+----+
| id |
+----+
|  4 |
|  9 |
| 10 |
+----+
3 rows in set (0.01 sec)

结果却非我们所猜想的???

继续插入值

mysql> insert into t2 values(null),(null),(null);
Query OK, 3 rows affected (0.05 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from t2;
+----+
| id |
+----+
|  4 |
|  9 |
| 10 |
| 30 |
| 35 |
| 40 |
+----+
6 rows in set (0.00 sec)

经过多组测试,结果依旧(试验其他值都是正常的,唯独上述有问题)

那么,

  问题来了auto_increment_offset=10和auto_increment_increment=5这一组数值算是MySQL自增长里的一个bug吗

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值