简体   繁体   中英

Mysql autoincrement bug in insert select

Can anyone suggest me the workaround for the following bug in mysql.

  http://bugs.mysql.com/bug.php?id=61058

This bug was reported long ago (2007) with mysql 5.0, but i am still facing same issue with mysql 5.6. I have followed this post which first gave some insight for this problem.

Mysql auto increment jumps when insert-select

Followed the post as some one suggested preferably setting

ALTER TABLE `test` AUTO_INCREMENT = 1; 

which will not work in my case where i have a stored procedure which will run in background as an event for a specified time.

Can anyone please suggest me for a workaround....??

Thanks in advance

首先,您应该确保mysql是最新的,其次要尝试重置自动增量,如下所示:

ALTER TABLE tablename AUTO_INCREMENT = 1

You can change innodb_autoinc_lock_mode=0 (“traditional” lock mode) from mysql.ini to avoid skipping values in primary key in some cases. See the manual innodb auto increment handling for more details.

As per manual 'The traditional lock mode option is provided for backward compatibility, performance testing, and working around issues with “mixed-mode inserts”, due to possible differences in semantics'.

'In this lock mode, all “INSERT-like” statements obtain a special table-level AUTO-INC lock for inserts into tables with AUTO_INCREMENT columns. This lock is normally held to the end of the statement (not to the end of the transaction) to ensure that auto-increment values are assigned in a predictable and repeatable order for a given sequence of INSERT statements, and to ensure that auto-increment values assigned by any given statement are consecutive'.

Another thing to check is the value of the auto_increment_increment config variable. It's 1 by default, but you may have changed this. it is very uncommon to set it to something higher than 1 or 2, but possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM