I have a table to make temporary id`s . When i delete all of the rows of my table , auto increment value for this table will reset to 0 . but i don't want to reset the auto increment. What can i do?
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
Compare TRUNCATE TABLE:
... with DELETE FROM:
Resetting auto increment value to 0 can be caused by a few reasons.
Reason 1
You use
TRANCATE table
to empty the table.TRUNCATE
not only deletes the rows but resets the auto increment value by design.Use
DELETE FROM table
instead.Reason 2
The table engine is InnoDB. InnoDB doesn't store auto increment value on disk thus forgets it when the MySQL server is shut down. When the MySQL is started again, the InnoDB engine restores the auto increment value this way:
SELECT (MAX(id) + 1) AS auto_increment FROM table
. This is a bug that is fixed in MySQL version 8.0.Change the table engine:
ALTER TABLE table ENGINE = MyISAM
. Or update the MySQL server to version 8.0 when it is released.