MySQL auto_increments 总是插入 2147483647

标签 mysql auto-increment

我在 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/

相关文章:

postgresql - 自动递增串行数据类型

Mysql auto_increment 从最低值开始

mysql - 为每个唯一组设置 auto_increment 值

MYSQL DateTime 查询以获取特定日期的值

MySQL - 批量插入带有日期时间和时间戳字段的数据

mysql - 我怎样才能实现这个mysql组查询

mySQL 更新接下来的 12 个 NULL 值,日期递增 1

php - SQL 查询的重复结果

mysql - 未找到 SQL 完整性约束父键

mysql - hibernate 不在 mysql 表上生成自动增量约束