Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

node.js - mySQL auto increment increasing by 10 (ClearDB & Node)

I have a simple table in 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:

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 username message

12 test test

22 test test

32 test test

42 test test

Any idea why this is happening?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is ClearDB's strategy. Here is the explanation from ClearDB's website.

You can't change this auto_increment step when you are using ClearDB.


This is the explanation from the link above.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...