Mysql 5.1.42 alter table auto_increment = 0 不起作用,truncate 起作用
对于我的自动验收测试,我希望插入以 id=1 开头。 我在一台PC(XP 32位,mysql 5.1.something)上通过(从表中删除所有行后)“alter table tableName auto_increment = 0”实现了这一点。
我现在正在设置一台新电脑(Windows 7 64位,mysql 5.1.42),这个命令似乎没有效果。 我可以在 information_schema.tables 表中看到 auto_increment 值没有改回 0 --- 它只是不断上升。如果我尝试直接更改该表中的值,我会被告知“root”@“localhost”的访问被拒绝。这是否暗示了我的问题?
其他 stackoverflow 人员建议“从 tableName 截断”是一个不错的选择。我很高兴地报告这有效。但有谁知道为什么“alter table”命令不会重置auto_increment?
谢谢!
For my automated acceptance tests, I want inserts to start with id=1.
I achieved this on one PC (XP 32bit, mysql 5.1.something) with (after deleting all rows from the table), "alter table tableName auto_increment = 0".
I'm now setting up a new PC (Windows 7 64bit, mysql 5.1.42), and this command seems to have no effect.
I can see in the information_schema.tables table that the auto_increment value is not changed back to 0 --- it just keeps going up. If I try to change the value in that table directly, I'm told that access is denied to 'root'@'localhost'. Does this perhaps give a hint to my problem?
Other stackoverflow people had suggested that "truncate from tableName" is a good alternative. I'm happy to report that this works. But does anyone know why the "alter table" command won't reset the auto_increment?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不知道为什么它在一台服务器上工作,而在另一台服务器上不起作用,但是 MySQL 手册指出 (引用,强调我的):
也许这就是问题的原因:您试图将
auto_increment
计数器设置回 0,但它已经高于该值 - 并且您无法将其重置为小于任何值的值已经用过了,没用。NOt sure why it worked on one server, and doesn't work on the other, but the MySQL manual states (quoting, emphasis mine) :
Maybe that's the cause of the problem : you are trying to put the
auto_increment
counter back to 0, but it's already higher than that value -- and as you cannot reset it to a value that's less than any value that's already been used, it doesn't work.