MySQL 记录被删除之后 AUTO_INCREMENT 值被复用问题分析
2017-06-05 22:02
671 查看
结论
MyISAM 不会出现删除掉的 AUTO_INCREMENT 字段值被复用的问题,因为这个最大值会被写磁盘,每次初始化会从磁盘读取InnoDB 会出现删除掉的 AUTO_INCREMENT 字段值被复用的问题,因为这个最大值不会写磁盘,每次都是用类似
SELECT MAX(ai_col) FROM table_name FOR UPDATE;的方式初始化。
参考
InnoDB AUTO_INCREMENT Counter InitializationIn MySQL 5.7 and earlier, the auto-increment counter is stored only in main memory, not on disk. To initialize an auto-increment counter after a server restart, InnoDB would execute the equivalent of the following statement on the first insert into a table containing an AUTO_INCREMENT column.
SELECT MAX(ai_col) FROM table_name FOR UPDATE;
In MySQL 8.0, this behavior is changed.
需要注意的是,5.7 及之前版本才会出现该问题。
相关文章推荐
- mysql实现插入一条记录时候还回主键值,表的主键是自增长方式AUTO_INCREMENT
- 解析mysql中的auto_increment的问题
- Failed to read auto-increment value from storage engine 诡异的mysql自增无效问题
- mysql中的auto_increment的问题
- mysql中unique key与auto_increment的性能分析
- MySQL 中 AUTO_INCREMENT 的“坑” --重复值问题
- MySQL生产库Insert了2次同样的记录但是主键ID是不一样的问题的分析过程
- mysql中自增auto_increment功能的相关设置及问题
- MySQL主从复制中关于AUTO_INCREMENT的奇怪问题
- MySQL生产库Insert了2次同样的记录但是主键ID是不一样的问题的分析过程
- Carte+kettle+mysql性能问题定位分析记录
- MySQL主从复制中关于AUTO_INCREMENT的奇怪问题
- mysql中自增auto_increment功能的相关设置及问题
- MySQL生产库Insert了2次同样的记录但是主键ID是不一样的问题的分析过程
- mysql自增auto_increment删除记录
- 解析mysql中的auto_increment的问题
- mysql innodb auto_increment id不连续增长问题
- MySQL auto_increment间隙问题
- MySQL生产库Insert了2次同样的记录但是主键ID是不一样的问题的分析过程
- MySQL主从复制中关于AUTO_INCREMENT的奇怪问题