我在带有 innodb 的 MySQL 中使用简单的 INSERT 语句,主 ID 自动递增。我是否需要担心如果用户 A 和用户 B 同时执行相同的脚本,用户 A 的插入会被用户 B 的插入覆盖?
最佳答案
不,不会。您可以将其视为线程安全的。
来自引用:
When accessing the auto-increment counter, InnoDB uses a special table-level AUTO-INC lock that it keeps to the end of the current SQL statement, not to the end of the transaction
http://dev.mysql.com/doc/refman/5.1/en/innodb-auto-increment-handling.html
关于带有自动增量的 MySQL 插入 - 是否需要插入忽略以避免并发问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16376689/