MySQL 5.7 description of parameters related to self-increasing fields
The auto_increment_increment and auto_increment_offset parameters are used in the master master replication to control the operation of the AUTO_INCREMENT field, and different generation rules are used in different nodes to avoid conflicts caused by the same generated sequence. These two parameters can set global and session variables, respectively, and the range of values for each parameter is 1: 65535. Setting these two parameters to 0 results in actually setting the value of these two parameters to 1.
The auto_increment_increment parameter controls the number of intervals between AUTO_INCREMENT field values
Mysql > SHOW VARIABLES LIKE 'auto_inc%'
+-+ +
| | Variable_name | Value |
+-+ +
| | auto_increment_increment | 1 | |
| | auto_increment_offset | 1 | |
+-+ +
2 rows in set (0.00 sec)
Mysql > CREATE TABLE autoinc1
-> (col int not null auto_increment primary key)
->
Query OK, 0 rows affected (0.12 sec)
Mysql > select @ @ auto_increment_increment
+-+
| | @ @ auto_increment_increment |
+-+
| | 1 |
+-+
1 row in set (0.00 sec)
Mysql > set @ @ auto_increment_increment=10
Query OK, 0 rows affected (0.06 sec)
Mysql > select @ @ auto_increment_increment
+-+
| | @ @ auto_increment_increment |
+-+
| | 10 |
+-+
1 row in set (0.00 sec)
Mysql > SHOW VARIABLES LIKE 'auto_inc%'
+-+ +
| | Variable_name | Value |
+-+ +
| | auto_increment_increment | 10 | |
| | auto_increment_offset | 1 | |
+-+ +
2 rows in set (0.00 sec)
Mysql > INSERT INTO autoinc1 VALUES (null), (null), (null)
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
Mysql > SELECT col FROM autoinc1
+-+
| | col |
+-+
| | 1 |
| | 11 |
| | 21 |
+-+
3 rows in set (0.00 sec)
The auto_increment_offset parameter determines the starting value of the AUTO_INCREMENT field
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 | |
+-+ +
2 rows in set (0.00 sec)
Mysql > CREATE TABLE autoinc2
-> (col int not null auto_increment primary key)
Query OK, 0 rows affected (0.64 sec)
Mysql > INSERT INTO autoinc2 VALUES (null), (null), (null)
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
Mysql > SELECT col FROM autoinc2
+-+
| | col |
+-+
| | 5 |
| | 15 |
| | 25 |
+-+
3 rows in set (0.00 sec)