mysql主键自增值和偏移量的查看和修改

版权声明:chaizepeng https://blog.csdn.net/chaizepeng/article/details/84450203

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

猜你喜欢

转载自blog.csdn.net/chaizepeng/article/details/84450203