MySQL auto increment ID suddenly jumped to MAXINT, what could be a reason?

戏子无情 提交于 2019-12-20 01:59:06

问题


I have a mysql table with about 2,000,000 entries, with a primary key which is auto incrementing. However, at one point the auto increment value suddenly jumped from what it was (around 2,000,000) to maximum integer value (2,147,483,647). Needless to say all subsequent insertions into this table failed. When I noticed it, I changed primary key type from int to bigint and so it works fine for now.

So my question is, why could this have happened? And are there any precautions which I could take to avoid this from happening in the future?


回答1:


A failed insert can still cause the auto-increment column to increase. If your program went into an infinite loop of failures it could cause the limit to be reached.

It's also possible to set the auto-increment programmatically to a specific value.

ALTER TABLE yourtable AUTO_INCREMENT = 12345;



回答2:


One reason for this could be-

If you entered random numbers in the column of auto increment, then it could be because auto_increment works only in ascending order. So when you inserted the number, which is near to maximum limit, then it reached the maximum limit soon and you couldn't enter anything else.



来源:https://stackoverflow.com/questions/10042042/mysql-auto-increment-id-suddenly-jumped-to-maxint-what-could-be-a-reason

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!