MySQL default self-increment ID is starting from 1, but when we have inserted a table or deleted ID by using delete, the ID will not start from 1.
When using MySQL, there is usually a self-increment ID field in the table, but when we want to empty the data in the table and re-add the data, we want the ID to be counted back from 1, in the following two ways:
The usual way to set the self-increment field:
Add when creating a table:
CREATE TABLE table1 (ID int auto_increment PRIMARY key,...)
After creating the table, add:
ALTER TABLE table1 Add ID int auto_increment primary key self-increment field, be sure to set to primary key.
Example
ALTER TABLE tablename drop column ID;
ALTER TABLE tablename Add ID mediumint (8) NOT NULL primary key auto_increment first;
Method Two:
ALTER TABLE TableName auto_increment=0
MySQL database self-increment ID re-ordered from 1 two methods