简体   繁体   English

mySQL 自动增量增加 10(ClearDB 和节点)

[英]mySQL auto increment increasing by 10 (ClearDB & Node)

I have a simple table in ClearDB:我在 ClearDB 中有一个简单的表:

CREATE TABLE `users` (

`id` smallint(6) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(100) DEFAULT NULL,
`message` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`)

) ENGINE=INNODB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

I'm using Node to insert data into the table via:我正在使用 Node 通过以下方式将数据插入表中:

var post = {username: response.user.name, message: message.text};

           connection.query("INSERT INTO users SET ?", post, function(err, rows, fields) {

                 if (err) {
                       console.log('error: ', err);
                       throw err;
                 }

           });

However whenever I insert my id field increases by 10 rather than 1 (and it started off with 12:但是,每当我插入我的 id 字段时,它都会增加 10 而不是 1(它以 12 开始:

id username message id 用户名消息

12 test test 12测试测试

22 test test 22测试测试

32 test test 32测试测试

42 test test 42测试测试

Any idea why this is happening?知道为什么会这样吗?

Thanks!谢谢!

It is ClearDB's strategy.这是 ClearDB 的策略。 Here is the explanation from ClearDB's website.这是来自 ClearDB 网站的解释。

You can't change this auto_increment step when you are using ClearDB.当您使用 ClearDB 时,您无法更改此 auto_increment 步骤。


This is the explanation from the link above.这是上面链接的解释。

ClearDB uses circular replication to provide master-master MySQL support. ClearDB 使用循环复制来提供主-主 MySQL 支持。 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.因此,在所有情况下,必须配置某些东西,例如 auto_increment 键(或序列),以便一个主服务器不使用与另一个相同的键。 We do this by configuring MySQL to skip certain keys, and by enforcing MySQL to use a specific offset for each key used.为此,我们将 MySQL 配置为跳过某些键,并强制 MySQL 为每个使用的键使用特定的偏移量。 The reason why we use a value of 10 instead of 2 is for future development.我们之所以使用值 10 而不是 2 是为了未来的发展。

I had the same problem.我有同样的问题。 After some digging I found that I can change the auto_increment经过一番挖掘,我发现我可以更改auto_increment

Check first what value it is首先检查它是什么值

SELECT @@auto_increment_increment

Then change it然后改变它

SET @@auto_increment_increment=1;

This seems to be because of AUTO_INCREMENT field这似乎是因为 AUTO_INCREMENT 字段
remove AUTO_INCREMENT=11删除AUTO_INCREMENT=11

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM