Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Auto increment with even or odd numbers only?

Tags:

mysql

Is it possible to have auto increment field which generates even or odd numbers (skips the opposite)? The reason I am asking is because I want to share auto increment between two tables. Other ways for achieving it are welcomed.

Thanks in advance!

like image 888
George Avatar asked May 27 '12 18:05

George


2 Answers

As mentioned by Juergen you could do that at system level instead of session level by making following change (or adding) in my.ini file:

auto-increment-increment = 2
auto-increment-offset = 1

or

auto-increment-increment = 2
auto-increment-offset = 2

Basically this is much used in Master-Master replication setup.

like image 82
deej Avatar answered Oct 06 '22 01:10

deej


try

SET @@auto_increment_increment=2;
SET @@auto_increment_offset=2;
like image 36
juergen d Avatar answered Oct 05 '22 23:10

juergen d