1、mysql自增步長不是1的解決辦法
查看配置:
show variables like ‘%increment%’;
如果:
auto_increment_increment=2
執行:
set @@global.auto_increment_increment = 1;
set @@auto_increment_increment =1;
如果:
auto_increment_offset=2
執行:
set @@global.auto_increment_offset =1;
set @@auto_increment_offset =1;
2、mysql自增id亂了重新排序的解決辦法
表名: user
- 刪除原有主鍵:
alter table user drop id;
- 添加新主鍵字段並設置主鍵:
alter table user add id int(11) not null first;
alter table user modify column id int(11) not null auto_increment,add primary key(id);
- 查看錶:
select * from user;
ps:如果曾經的數據都不需要的話,可以直接清空所有數據,並將自增字段恢復從1開始計數
truncate table user;