1. 程式人生 > >mysql主鍵自增值和偏移量的檢視和修改

mysql主鍵自增值和偏移量的檢視和修改

1、檢視mysql自增值和偏移量

show variables like '%increment%';

auto_increment_increment=1  -- 自增倍數是1

auto_increment_offset=1 -- 偏移量是1

上邊這是一般的設定,每次每次主鍵自增的倍數是1,偏移量是1

例如:插入第n條記錄,那麼它的 主鍵值 =  (n-1)*auto_increment_increment + auto_increment_offset

2、修改自增值

set @@global.auto_increment_increment = 2; 

set @@auto_increment_increment =2;

3、修改偏移量

set @@global.auto_increment_offset = 2;

set @@auto_increment_offset = 2