In MySQL, I have a table, and I want to set the auto_increment
value to 5
instead of 1
. Is this possible and what query statement does this?
相关问题
- 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
Yes, you can use the
ALTER TABLE t AUTO_INCREMENT = 42
statement. However, you need to be aware that this will cause the rebuilding of your entire table, at least with InnoDB and certain MySQL versions. If you have an already existing dataset with millions of rows, it could take a very long time to complete.In my experience, it's better to do the following:
In this way, even if you're rolling back the transaction, MySQL will keep the auto-increment value, and the change will be applied instantly.
You can verify this by issuing a
SHOW CREATE TABLE t
statement. You should see: