一、ID中断不连续的,重新设置为连续的ID
alter table table_name drop id;
alter table table_name add id int not null first;
alter table table_name modify column id int not null auto_increment, add primary key(id);
select * from table_name order by id;
二、根据日期顺序,重新排列ID
alter table table_name drop id;
alter table table_name add id int not null first;
SET @row_number = 0;
UPDATE table_name
SET id = (@row_number := @row_number + 1)
ORDER BY ref_date;
alter table table_name modify column id int not null auto_increment, add primary key(id);
select * from table_name order by id;
参考文章: