【问题标题】:MySQL - Can't set auto-increment value of tables to lower valueMySQL - 无法将表的自动增量值设置为较低的值
【发布时间】:2013-05-21 16:02:03
【问题描述】:

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

【问题讨论】:

  • 如果我理解正确,你有第 7 8 9 行,你删除它们,你想让 A_I 再次从 7 开始统计?
  • @Nikola 是的,你理解正确

标签: mysql phpmyadmin auto-increment


【解决方案1】:

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

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

【讨论】:

  • 重新启动 MySQL 服务器为我修复了这个数字,感谢您的提示!
  • 重新启动 MySQL 服务器修复了我的表的数量。很好的答案。谢谢
  • 也为我工作 - 很棒的提示
【解决方案2】:

来自手册:

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.

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

【讨论】:

  • 谢谢,它确实是一个正在使用的 InnoDB 引擎。切换到 MyISAM 让我可以降低自动增量。
【解决方案3】:

感谢大佬的正确回答。

InnoDB 的解决方法

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

只需确保在重新加载之前删除表即可;你可能需要通过禁用密钥检查 SET foreign_key_checks = 0;

【讨论】:

  • 你的答案确实是正确的。更简单的解决方案是:更改表格,删除自动增量选项,根据要求删除或更新这些字段,然后再次重新设置自动增量。
猜你喜欢
  • 2011-11-25
  • 2012-11-30
  • 2017-09-16
  • 2011-06-06
  • 2016-03-13
  • 2018-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多