MySQL autoincrement column jumps by 10- why?
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:
Why does it do that?
Is that a problem?
Please do not change the auto_increment_increment
. ClearDB is doing this on purpose. It's explained in the documentation:
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.
Check to see the seed value of the autoincrement isn't set to 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=1;
If you want to start the values at a number other than one you can go:
ALTER TABLE tbl AUTO_INCREMENT = 100;
Thanks @Jim Fiorato for providing the link.
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 |
+--------------------------+-------+
The auto increment increment value is set in the MySQL system variables.
See here: http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#option_mysqld_auto-increment-increment