天天看点

MySQL中自增ID起始值修改方法

在实际测试工作过程中,有时因为生产环境已有历史数据原因,需要测试环境数据id从某个值开始递增,此时,我们需要修改数据库中自增ID起始值,下面以MySQL为例:

表名:users;

建表时添加:

create table users(id int auto_increment primary key,666);

表已创建,修改:

alter table users add id int auto_increment primary key; #将自增字段设置为primary key

alter table users AUTO_INCREMENT=10000;