我在 PHP 中有以下 SQL 代码
$conn->query("INSERT INTO orders (Name,Email,phone) VALUES
('$name','$email','$phone')");
我的数据库表有 ID、姓名、电子邮件、电话
插入成功,但 id 始终设置为 2147483647,即最大 int(11)
所以我的表格中只有一行
ID-------------姓名--------电子邮件-----电话
2147483647--约翰--史密斯--John@John.com--04524524
id字段设置为自动增量
不再是 1 或 2,而是一直达到最大值 (2147483647)
即使我设置 BIGINT 或更改类型 mysql 也会插入最大 ID 增量
最佳答案
您可以通过以下方式重置计数器:
ALTER TABLE tablename AUTO_INCREMENT = 1
对于 InnoDB,您不能将 auto_increment
值设置为低于或等于当前最高索引。 (引自 [ViralPatel][1]):
Note that 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.
如果您只是引导数据库,您可能应该考虑使用以下方法清空表:
TRUNCATE TABLE tablename;
上面的命令还将重置所有自动计数器。
关于MySQL auto_increments 总是插入 2147483647,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54391119/