我有 2 个不同的 MySQL 服务器。 一个是 5.6.12,另一个是 5.5.25a。
在5.5版本的服务器中我可以这样做:
ALTER TABLE AUTO_INCREMENT = 100;
ALTER TABLE AUTO_INCREMENT = 50;
5.6 版本只允许我将 auto_increment 更改为比当时的 auto_increment 更高的值。
当然,我并不是要将值更改为低于具有最大值的记录的值。
两台MySQL服务器都是InnoDB
我需要在最新版本中使用那个commen
有什么线索吗?
最佳答案
此查询适用于 mysql 5.6.12 和 5.5.25:
ALTER TABLE `table_name` AUTO_INCREMENT =10
根据 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.
如果表没有记录,可以使用TRUNCATE
:
TRUNCATE TABLE table_name
来自 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.
更新:mysql5.6.12 似乎有一些错误:http://bugs.mysql.com/bug.php?id=69882
关于MySQL 自动递增?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18418471/