9

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!

Chris Olson
  • 1,021
  • 4
  • 12
  • 19

3 Answers3

15

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.

Jeff
  • 524
  • 5
  • 17
  • This looks like a good answer to the question (thanks!), but could you [edit] and include the relevant information from the website in your answer? That way all information is preserved here, in case the link or content there changes. – user812786 Aug 02 '16 at 15:10
  • @whrrgarbl Thanks, I did. :) – Jeff Aug 02 '16 at 15:30
4

I had the same problem. After some digging I found that I can change the auto_increment

Check first what value it is

SELECT @@auto_increment_increment

Then change it

SET @@auto_increment_increment=1;
Chirag Bhatia - chirag64
  • 4,430
  • 3
  • 26
  • 35
abdelhamied mostafa
  • 215
  • 1
  • 3
  • 14
0

This seems to be because of AUTO_INCREMENT field
remove AUTO_INCREMENT=11

Sachin
  • 1,208
  • 1
  • 10
  • 20