mysql_insert_id issue in concurrency data inserting(并发数据插入中的mysql_insert_id问题)
问题描述
mysql_insert_id() 在竞争条件下的可靠性如何?我的意思是当多个用户同时插入数据时,这个函数是返回真实的ID还是返回其他用户插入的数据ID?
How reliable is mysql_insert_id() in a competitive condition? I mean when multiple users are inserting data at the same time, will this function return the true ID or it will return other user's inserted data ID?
表引擎是 MyISAM.
The table engine is MyISAM.
推荐答案
mysql_insert_id 是完全多用户安全的,完全依赖数据库连接,每个连接只能有一个用户....所以,根据你的问题,它返回真实的 id....
mysql_insert_id is completely multi-user safe.It is entirely relies upon the database connection, and you can only have one user per connection....So, as per your question, it returns true id....
来自 MySql 文档,
生成的 ID 在服务器上维护每个连接的基础.这意味着返回的值给定客户端的函数是生成的第一个 AUTO_INCREMENT 值对于影响 AUTO_INCREMENT 列的最新语句客户.该值不会受到其他客户端的影响,即使他们生成自己的 AUTO_INCREMENT 值.这种行为确保每个客户端都可以检索自己的 ID 而不用关心其他客户端的活动,并且不需要锁或交易.
The ID that was generated is maintained in the server on a per-connection basis. This means that the value returned by the function to a given client is the first AUTO_INCREMENT value generated for most recent statement affecting an AUTO_INCREMENT column by that client. This value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that each client can retrieve its own ID without concern for the activity of other clients, and without the need for locks or transactions.
这篇关于并发数据插入中的mysql_insert_id问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:并发数据插入中的mysql_insert_id问题
基础教程推荐
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 在多列上分布任意行 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
