Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2019/02/21--一张表里面有ID自增主键,当insert了17条记录之后,删除了第15,16,17条记录,再把mysql重启,再insert一条记录,这条记录的ID是18还是15 ? #23

Open
lq920320 opened this issue Feb 21, 2019 · 0 comments

Comments

@lq920320
Copy link
Owner

如果你的表类型是InnoDB,那么,新纪录的ID为15;如果你的表类型是MyISAM,那么,新纪录的ID为18。

这是因为:InnoDB类型的数据表将表最后的ID值保存在内存里面。所以,当我们重新启动服务器后,内存里面的数据清空,那么自增的ID将重新按照现有表的纪录计算;相反,如果是MyISAM类型的数据表,将最大纪录ID保持在文件里,这样,虽然,重启了服务器,下次插入新纪录的时候,自增ID通过读取文件而计算得到。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant