简体   繁体   English

mysql autoincrement在innodb中不是顺序的

[英]mysql autoincrement is not sequential in innodb

Mysql autoincrmenting is not sequential. Mysql自动递增不是顺序的。

when i was trying to upload csv bulk data it's skipping some of the auto increment id 当我尝试上传CSV批量数据时,它跳过了一些自动增量ID

The auto increment id is not sequential 自动增量编号不是顺序的

The db engine is innodb & id is auto increment 数据库引擎是innodb&id是自动递增

example

id      color 
    1      red
    2      blue
    3      green
    4      orange
    9      pink
    10     white
    11     black 
    16     gray
    17     brown

The id is not sequential. 该ID不连续。

don't know about codeignitor and specifics of transactions, but i do know that "catched fails" in queries (like insert ignore ) have the effect of NOT inserting, but DO increment the auto_increment. 我不了解codeignitor和事务的详细信息,但我确实知道查询中的“捕获失败”(例如insert ignore )具有不插入的效果,但是可以增加auto_increment的值。 Look for your answer here. 在这里寻找您的答案。 And for the rest don't bother 'fixing' this. 其余的不用理会。

If you are using MySQL newer than 5.1.22 this can be caused because of the InnoDB locking strategy as Miguel Angel Nieto explains in this blog post . 如果您使用的MySQL版本高于5.1.22则可能是由于InnoDB 锁定策略引起的,正如Miguel Angel Nieto在此博客文章中所述

You can change this behavior setting the innodb_autoinc_lock_mode parameter: 您可以通过设置innodb_autoinc_lock_mode参数来更改此行为:

  • innodb_autoinc_lock_mode = 0 : “traditional” lock mode , same behavior as before 5.1.22 innodb_autoinc_lock_mode = 0“传统”锁定模式 ,与5.1.22之前的行为相同
  • innodb_autoinc_lock_mode = 1 : “consecutive” lock mode , default behavior, this is probably what you have set, it's designed to improve concurrency and performance with the drawback of having holes on the sequence. innodb_autoinc_lock_mode = 1“连续”锁定模式 ,默认行为,这可能是您设置的值,它旨在提高并发性和性能,但缺点是在序列上有漏洞
  • innodb_autoinc_lock_mode = 2 : “interleaved” lock mode , this is the fastest and most scalable lock mode, but it is not safe when using statement-based replication or recovery scenarios when SQL statements are replayed from the binary log innodb_autoinc_lock_mode = 2“交错”锁定模式 ,这是最快,可扩展性最高的锁定模式,但是当使用基于语句的复制或恢复方案从二进制日志中重播SQL语句时, 这是不安全的

For a detailed information o the use of innodb_autoinc_lock_mode you can check the detailed mysql documentation . 有关使用innodb_autoinc_lock_mode的详细信息,可以查看详细的mysql文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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