gpt4 book ai didi

Mysql 5.1.42 alter table auto_increment = 0 不起作用,truncate 可以

转载 作者:行者123 更新时间:2023-11-29 04:31:16 25 4
gpt4 key购买 nike

对于我的自动验收测试,我希望插入以 id=1 开头。我在一台 PC(XP 32 位,mysql 5.1.something)上实现了这一点(从表中删除所有行后),“alter table tableName auto_increment = 0”。

我现在正在设置一台新PC(Windows 7 64位,mysql 5.1.42),这个命令似乎没有效果。我可以在 information_schema.tables 表中看到 auto_increment 值没有改回 0 --- 它一直在上升。如果我尝试直接更改该表中的值,我会被告知对“root”@“localhost”的访问被拒绝。这是否暗示了我的问题?

其他 stackoverflow 人员建议“从 tableName 截断”是一个不错的选择。我很高兴地报告这有效。但是有人知道为什么“alter table”命令不会重置 auto_increment 吗?

谢谢!

最佳答案

不确定为什么它在一台服务器上工作,而在另一台服务器上不工作,但是 MySQL manual states (引用,强调我的):

To change the value of the AUTO_INCREMENT counter to be used for new rows, do this:

ALTER TABLE t2 AUTO_INCREMENT = value;

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.

也许这就是问题的原因:您正试图将 auto_increment 计数器设置回 0,但它已经高于该值——并且您无法将其重置为更小的值比已使用的任何值都无效。

关于Mysql 5.1.42 alter table auto_increment = 0 不起作用,truncate 可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2032983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com