5

在删除表中的行后,我曾经能够将自动增量值设置为低于现有值,但现在我无法这样做(我只能将其设置为高于当前值)。我想知道这是否是因为升级了 MySQL (5.6.11)/PHPMyAdmin (3.5.8),或者我是否应该仍然能够这样做?

4

3 回答 3

10

您可以通过重新启动 MySQL 服务器来重置隐藏值。InnoDB 在重启后重新计算自动增量值。

更新您的行,然后重新启动 mysql 守护程序。这可以防止你重建你的桌子,因为大桌子可能会很麻烦。

于 2014-03-07T09:21:53.550 回答
9

从手册:

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.

所以简而言之,它取决于使用的存储引擎。

于 2013-05-26T18:30:36.533 回答
3

感谢您的正确答案,大亨。

InnoDB 的解决方法:

  • 把桌子倒掉,
  • 更改转储文件中的自动增量值,以及
  • 重新加载它

只需确保在重新加载之前放下表格即可;并且您可能需要通过 SET foreign_key_checks = 0 禁用密钥检查;

于 2014-02-27T06:08:40.830 回答