问题
I have 2 different MySQL servers. One is 5.6.12 the other 5.5.25a.
In the 5.5 version server I can do this:
ALTER TABLE AUTO_INCREMENT = 100;
ALTER TABLE AUTO_INCREMENT = 50;
The 5.6 version only allows me to change the auto_increment to a higher value than auto_increment is in that moment.
Of course I'm not trying to change the value to a lower value than the record that has the maximum value.
Both MySQL servers are InnoDB
I need to use that commen in the newest version
Any clue?
回答1:
This query works in both mysql 5.6.12 and 5.5.25:
ALTER TABLE `table_name` AUTO_INCREMENT =10
According to mysql manual:
You cannot reset the counter to a value less than or equal to any that have already been used. For MyISAM, if the value is less than or equal to the maximum value currently in the AUTO_INCREMENT column, the value is reset to the current maximum plus one. For InnoDB, if the value is less than the current maximum value in the column, no error occurs and the current sequence value is not changed.
If the table has no records, you can use TRUNCATE
:
TRUNCATE TABLE table_name
From mysql manual:
Any AUTO_INCREMENT value is reset to its start value. This is true even for MyISAM and InnoDB, which normally do not reuse sequence values.
UPDATE: It looks like there is some bug with mysql5.6.12: http://bugs.mysql.com/bug.php?id=69882
来源:https://stackoverflow.com/questions/18418471/mysql-auto-increment