mySQL自动增量问题:重复条目'4294967295'对于钥匙 1

发布于 2024-08-27 11:53:57 字数 763 浏览 13 评论 0原文

我有一个电子邮件表。

自动增量 ID 的最后一条记录是 3780,这是一条合法记录。我现在插入的任何新记录都将被插入那里。

然而,在我的日志中,我偶尔会遇到这样的情况:

Query FAIL: INSERT INTO mail.messages (timestamp_queue) VALUES (:time);
Array
(
    [0] => 23000
    [1] => 1062
    [2] => Duplicate entry '4294967295' for key 1
)

不知何故,自动增量跳到了 INT 最大值 4294967295

为什么在上帝的绿色地球上这会跳得这么高?我没有带有 id 字段的插入。

该表 Auto_increment 表的显示状态现在显示为: 4294967296

怎么会发生这样的事情?我意识到 id 字段也许应该是一个大整数,但我担心的是这个东西会以某种方式跳回来。

Josh

编辑:更新

mysql 版本 5.0.45 red hat patched

自从我将 id 设置为 BIGINT 后,最后几个 id 看起来像:

3777
3778
3779
3780
4294967295
4294967296
4294967297
4294967298
4294967299
4294967300

如您所见,它们是增量的,没有间隙(到目前为止)。太奇怪了。

I have a table of emails.

The last record in there for an auto increment id is 3780, which is a legit record. Any new record I now insert is being inserted right there.

However, in my logs I have the occasional:

Query FAIL: INSERT INTO mail.messages (timestamp_queue) VALUES (:time);
Array
(
    [0] => 23000
    [1] => 1062
    [2] => Duplicate entry '4294967295' for key 1
)

Somehow, the autoincrement jumped up to the INT max of 4294967295

Why on god's green earth would this get jumped up so high? I have no inserts with an id field.

The show status for that table, Auto_increment table now reads: 4294967296

How could something like this occur? I realize the id field should perhaps be a big int, but the worry I have is that somehow this thing jumps back up.

Josh

Edit: Update

mysql version 5.0.45 red hat patched

Since I set the id to BIGINT the last few id's look like:

3777
3778
3779
3780
4294967295
4294967296
4294967297
4294967298
4294967299
4294967300

As you can see, they are incremental, with no gaps (so far). Totally weird.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

辞别 2024-09-03 11:53:57

我也遇到了同样的问题,而且号码完全相同。我的问题是,当我将 int(10) 上的字段更改为 bigint(20) 时,它解决了我的问题。

如果其他人也遇到这个问题。首先检查您的字段大小。 :)

I had the same problem with the exact same number. My problem was that I had the field on int(10) when I changed it to bigint(20) it solved my problem.

If others are having this problem. Check your field size first. :)

墨小沫ゞ 2024-09-03 11:53:57

我仍然不完全清楚这里发生了什么,但我想我会跟进。

在我的持久化引擎中,我有一种类型的带有自动增量 id 的对象,以及带有 GUID id 的子类。

显然,两人是不相容的。我有理由将对象转换为其父对象,然后保存它(基本上子类是具有附加功能的电子邮件模板,但是当我想实际发送电子邮件时,我将其转换为父对象并将其保存到常规外发邮件队列)。愚蠢的是,我没有意识到 id 格式是不同的。这导致尝试将包含 36 个字符长字符串的记录插入到 int 中。准备好的语句中的字符串解析为“0”,无论出于何种原因,这都会导致自动增量系统 WIG OUT 并最大化原始表上的 INT 自动增量 id 字段。

长话短说,幸好我保留了日志。

乔什

Its still not totally clear to me what happened here, but I thought I'd follow up.

In my persistence engine, I had one type of object with a auto-increment id, and a subclass with a GUID id.

Obviously the two were incompatible. I have a reason to convert the object to its parent and then save it (basically the subclass is an email TEMPLATE that has additional functionality, but when i want to actually SEND the email, I convert it to the parent object and save it to the regular outgoing mail queue). Stupidly, I didn't realize the id formats were different. This resulted in trying to insert a record with a 36 character long string into an int. The string resolved to '0' in the prepared statement and for whatever reason this cause the auto-increment system to WIG OUT and max out the INT auto increment id field on the original table.

Long story short, good thing I was keeping logs.

Josh

断念 2024-09-03 11:53:57

当您意外插入新记录并提供 auto_increment 值时,通常会发生这种情况。

大多数情况下,这是因为您有一个具有相似名称的列,并且您犯了一个拼写错误,导致 auto_increment 值更新为您提供的值,如果您提供的是字符串而不是 int,则为 4294967295。

解决方法:

  • 删除 PK 值为 4294967295 的记录,
  • 通过运行检查最大增量值是多少
从 tableNameHere 中选择 max(autoincrementColumNameHere)
  • 通过运行更新您的 AUTO_INCRMENT 值
 ALTER TABLE tableNameHere AUTO_INCRMENT = (maxValue+1)

This usually happens when you accidentally insert a new record a provide the auto_increment value.

Most of the time that's because you have a column with a similar name and you make a typo that leads to the auto_increment value updated with the one you provided, which is 4294967295 if you provided a string instead of an int.

To solve this:

  • delete the record whose PK value is 4294967295,
  • check what was the max increment value by running
select max(autoincrementColumNameHere) from tableNameHere
  • update your AUTO_INCREMENT value by running
 ALTER TABLE tableNameHere AUTO_INCREMENT = (maxValue+1)
北斗星光 2024-09-03 11:53:57

通过 phpmyadmin,您可以使用该表的操作选项卡更改最后一个 id

by phpmyadmin simply you can change last id with operations tab of that table

情仇皆在手 2024-09-03 11:53:57

这实际上也发生在我身上(仍然不知道为什么)。我凭直觉这样做了:

ALTER TABLE  `{table name here}` AUTO_INCREMENT = {your number here};
FLUSH TABLE `{table name here}`;

而且似乎已经解决了这个问题。首先,我尝试先设置自动增量值,但它又回到了 4294967295。同样,不确定为什么更改增量值和刷新起作用(我不是数据库人员),但我想我应该将其发布在这里,因为它可能会帮助别人。

This actually just happened to me too (still not sure why). On a hunch I did:

ALTER TABLE  `{table name here}` AUTO_INCREMENT = {your number here};
FLUSH TABLE `{table name here}`;

and it seems to have fixed it. First I tried just setting the auto increment value first but it went back to 4294967295. Again, not sure why changing the increment value and flushing worked (I'm not a database guy), but I figured I'd post this here as it may help others.

肩上的翅膀 2024-09-03 11:53:57

只需将其更改为 BIGINT,您就可以创建“一些”额外的新记录。几千亿……;)

Just change it to a BIGINT and you can create "some" extra new records. A couple of hundred billion... ;)

酒几许 2024-09-03 11:53:57

这也发生在我身上。这个问题很愚蠢。

如果它收到一个字符串,它会将其转换为0,如果是整数,就像我的例子一样,我试图插入一个手机号码(在印度它是10)数字并以 9 开​​头,如9123456789) 到 int` 类型列中。

但是,signed int 的限制是 2147483647

我尝试将其转换为无符号,但限制仍然是4294967295。因此出现错误“4294967295”,但是当我将其转换为 bigint 时,其限制为 9223372036854775807 (对于 10 位手机号码来说更多),它开始接受它。

为了移动端,我将其转换为 unsigned ,这将其限制增加到 18446744073709551615

It happened to me too. The problem is a silly one.

If it receives a character string it converts it 0 and if integer, as in my case, where i was trying to insert a mobile no (in india it's 10 digits and starts with 9 like9123456789) into aint` type column.

However, the limit for signed int is 2147483647.

I tried converting it to unsigned, but still the limit is 4294967295. Thus error "4294967295" something, but when I converted it to bigint, which has a limit of 9223372036854775807 (which is more for 10 digit mobile no), it started to accept it.

For the sake of mobile no I converted it to unsigned which increased its limit to 18446744073709551615.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文