mysql表中已有数据,为表新增一个自增id。

第一步,在navicat中,例如表test新建查询,输入以下两行代码即可搞定。

alter table test add id int;
alter table `test` change id id int not null auto_increment primary key;

第二步,右键test表,设计,将id移动至第一行就可。

原文地址:https://www.cnblogs.com/loren880898/p/13321420.html