MySQL MySQL自动增量列跳了10-为什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/206751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:14:35  来源:igfitidea点击:

MySQL autoincrement column jumps by 10- why?

mysql

提问by user1709374

I have a couple tables in which I created an object ID as either an Int or Bigint, and in both cases, they seem to autoincrement by 10 (ie, the first insert is object ID 1, the second is object ID 11, the third is object ID 21, etc). Two questions:

我有几个表,我在其中创建了一个对象 ID 作为 Int 或 Bigint,在这两种情况下,它们似乎都会自动递增 10(即,第一个插入是对象 ID 1,第二个是对象 ID 11,第三个是是对象 ID 21 等)。两个问题:

  1. Why does it do that?

  2. Is that a problem?

  1. 为什么这样做?

  2. 那是问题吗?

回答by JamesSugrue

Check to see the seed value of the autoincrement isn't set to 10.

检查以查看自动增量的种子值未设置为 10。

You can check by:

您可以通过以下方式检查:

SELECT Auto_increment FROM information_schema.tables WHERE table_name='the_table_you_want';

As noted elsewhere you can change by using the system variable @@set_auto_increment_increment

如其他地方所述,您可以使用系统变量 @@set_auto_increment_increment 进行更改

SET @@auto_increment_increment=1;

If you want to start the values at a number other than one you can go:

如果你想以一个非 1 的数字开始值,你可以去:

ALTER TABLE tbl AUTO_INCREMENT = 100;

回答by user1709374

Please do not change the auto_increment_increment. ClearDB is doing this on purpose. It's explained in the documentation:

请不要更改auto_increment_increment. ClearDB 是故意这样做的。它在文档中解释:

ClearDB uses circular replication to provide master-master MySQL support. As such, certain things such as auto_increment keys (or sequences) must be configured in order for one master not to use the same key as the other, in all cases. We do this by configuring MySQL to skip certain keys, and by enforcing MySQL to use a specific offset for each key used. The reason why we use a value of 10 instead of 2 is for future development.

ClearDB 使用循环复制来提供主-主 MySQL 支持。因此,在所有情况下,必须配置某些东西,例如 auto_increment 键(或序列),以便一个主服务器不使用与另一个相同的键。为此,我们将 MySQL 配置为跳过某些键,并强制 MySQL 为每个使用的键使用特定的偏移量。我们之所以使用值 10 而不是 2 是为了未来的发展。

回答by user427969

Thanks @Jim Fiorato for providing the link.

感谢@Jim Fiorato 提供链接。

To check how much the auto increment value increments by, use the following query:

要检查自动增量值增加了多少,请使用以下查询:

SHOW VARIABLES LIKE 'auto_inc%';

+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| auto_increment_increment | 10    |
| auto_increment_offset    | 4     |
+--------------------------+-------+

回答by Jim Fiorato

The auto increment increment value is set in the MySQL system variables.

自动增量增量值在 MySQL 系统变量中设置。

See here: http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#option_mysqld_auto-increment-increment

见这里:http: //dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#option_mysqld_auto-increment-increment

回答by kimon

autoincriment value can jump if using insert with IGNORE attribute in case when record was not created

如果在未创建记录的情况下使用带有 IGNORE 属性的插入,则 autoincriment 值可以跳转

insert IGNORE into my_table set column=1