MySQL中,系统变量auto_increment_incrementauto_increment_offset是与自增列相关的两个参数变量。在官方文档中,将其划分为Replication Master Options and Variables 。具体参考官方文档17.1.6.2 Replication Master Options and Variables

 

    auto_increment_offset     AUTO_INCREMENT列值的起点,也就是初始值。取值范围是1 .. 65535

   auto_increment_increment   控制列中的值的增量值,也就是步长。其默认值是1,取值范围是1 .. 65535

 

系统变量auto_increment_incrementauto_increment_offset 都有会话级别和全局级别两个值(注意:设置全局系统变量时,对当前连接或已存在的连接不生效,只对新的连接有效)。它们的取值范围为1 ..65535, 如果设置的时候超过这个范围的话,会是什么情况? 如下所示:

 

mysql> show variables like 'auto_increment%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 1     |
| auto_increment_offset    | 1     |
+--------------------------+-------+
4 rows in set (0.00 sec)
 
mysql> set session auto_increment_increment=0;
Query OK, 0 rows affected, 1 warning (0.01 sec)
 
mysql> show variables like 'auto_increment%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 1     |
| auto_increment_offset    | 1     |
+--------------------------+-------+
2 rows in set (0.00 sec)
 
mysql>  set session auto_increment_increment=65536;
Query OK, 0 rows affected, 1 warning (0.00 sec)
 
mysql>  show variables like 'auto_increment%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 65535 |
| auto_increment_offset    | 1     |
+--------------------------+-------+
2 rows in set (0.00 sec)
 
mysql> 
mysql> set session auto_increment_offset=-1;
Query OK, 0 rows affected, 1 warning (0.04 sec)
 
mysql> show variables like 'auto_increment%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 65535 |
| auto_increment_offset    | 1     |
+--------------------------+-------+
2 rows in set (0.00 sec)

相关文章:

  • 2021-07-24
  • 2021-06-25
  • 2021-11-17
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
猜你喜欢
  • 2021-11-20
  • 2022-12-23
  • 2021-11-19
  • 2021-09-21
  • 2022-12-23
  • 2021-06-17
  • 2022-12-23
相关资源
相似解决方案