auto_increment_increment 和 auto_
2020-11-24 本文已影响0人
醉红尘丶
- auto_increment_increment 和 auto_increment_offset :长度限制 1-65535
- 一般 auto_increment_increment 值更改是由于主主复制或MGR架构所需,正常这俩个值均不会更改。
- auto_increment_increment : 设置间隔步长
- auto_increment_offset:设置初始值,且影响auto_increment值
- 当 auto_increment_offset > auto_increment_increment 时,auto_increment_offset被默认设置为1
- 当 auto_increment_offset <= auto_increment_increment,自增值计算方式是这样的:值 = auto_increment_offset + N*auto_increment_increment
mysql> set auto_increment_increment = 5;
Query OK, 0 rows affected (0.00 sec)
mysql> set auto_increment_offset=2;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%auto_incre%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| auto_increment_increment | 5 |
| auto_increment_offset | 2 |
+--------------------------+-------+
2 rows in set (0.00 sec)
mysql> create table t(id int auto_increment primary key);
Query OK, 0 rows affected (0.04 sec)
mysql> insert into t values(NULL), (NULL), (NULL), (NULL);
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select * from t;
+----+
| id |
+----+
| 2 |
| 7 |
| 12 |
| 17 |
+----+
4 rows in set (0.00 sec)