創建表格時添加: create table table1(id int auto_increment primary key,...) 創建表格后添加: 刪除原有主鍵: ALTER TABLE `table_name` DROP `id`; alter table table1 add id int auto_increment primary key 自增字段,一定要設置為primary key. 例子 alter table tablename drop column id; alter table tablename add id mediumint(8) not null primary key auto_increment first; 方法二: alter table tablename auto_increment=0