2013-05-26 27 views
4

我以前可以在刪除表格中的行後將自動增量值設置爲低於現有值,但現在我無法做到所以(我只能將它設置爲高於當前值)。我想知道這是因爲升級MySQL(5.6.11)/ PHPMyAdmin(3.5.8),還是我仍然可以做到這一點?MySQL - 無法將表格的自動增量值設置爲較低值

+0

如果我理解正確,你有行7 8 9,你刪除它們,你希望A_I從7再次統計? – Nikola

+0

@Nikola是的,你理解我正確 – Nick

回答

8

從手冊:

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. 

因此,在短期,這取決於所使用的存儲引擎。

+0

謝謝,這確實是一個InnoDB引擎正在使用。切換到MyISAM允許我降低自動增量。 – Nick

+0

你今天節省了我幾個小時,謝謝主席 – Pascamel

2

感謝您的正確答案,大人物。

變通InnoDB的

  • 轉儲出表,
  • 改變轉儲文件的自動增量值,
  • 重新加載它

只要確保在重新加載之前刪除表格;您可能需要通過 禁用密鑰檢查SET foreign_key_checks = 0;

+0

你的回答的確是對的。更簡單的解決方案是:更改表格,刪除自動增量選項,根據要求刪除或更新這些字段,然後重新設置自動增量。 – CodingMate

9

您可以通過重新啓動MySQL服務器來重置隱藏值。 InnoDB重新啓動後重新計算自動增量值。

更新您的行,並重新啓動mysql deamon。這可以防止你重建你的桌子,這可能是大桌子上的ha what。

+0

重新啓動MySQL服務器修復了我的號碼,謝謝你的提示! – SeinopSys

+0

重新啓動MySQL服務器修復了我的表的編號。好的答案。謝謝 – masterdany88

+0

也爲我工作 - 偉大的提示 – Sol

相關問題