# Custom id field auto\_increment increment and offset?

**URL:** <https://www.ruby-forum.com/t/custom-id-field-auto-increment-increment-and-offset/102235>\
**Category:** Rails\
**Created:** [August 13, 2006, 8:06pm UTC](https://www.ruby-forum.com/t/custom-id-field-auto-increment-increment-and-offset/102235 "2006-08-13T20:06:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![giuseb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@giuseb](https://www.ruby-forum.com/u/giuseb)\
**Post date:** [August 13, 2006, 8:06pm UTC](https://www.ruby-forum.com/t/custom-id-field-auto-increment-increment-and-offset/102235/1 "2006-08-13T20:06:02Z")

</div>

Hi all,  
in mysql, you can set the following environment variables:

set @@auto\_increment\_offset = 4;  
set @@auto\_increment\_increment =10;

such that:

create table people (id int auto\_increment primary key, name char(100));  
insert into people set name=‘Giuseppe’;  
insert into people set name=‘Laura’;  
select \* from people;  
±—±---------+  
| id | name |  
±—±---------+  
| 4 | Giuseppe |  
| 14 | Laura |  
±—±---------+

As you can see, thosee two variables determine the id that will be used  
for the first insert, and the increment for all subsequent inserts.

ActiveRecord seems to ignore this. In fact, if you use Rails to append  
new records to this table, the third row will get an id of 15 (instead  
of 24, as I would like).

I have unsuccessfully gone through the AR lib in search of the mechanism  
used by AR to determine ids for new records in a mysql connection.

Could anyone suggest a DRY way to either get AR to follow the scheme set  
in mysql or to override AR’s behavior and impose custom  
increment/offsets for id fields?

Incidentally, this request stems from the need to set up multiple-master  
database replication  
([Radar – O’Reilly](http://www.onlamp.com/pub/a/onlamp/2006/04/20/advanced-mysql-replication.html?page=1))

Cheers, Giuseppe
