并发数据插入中的mysql_insert_id问题 [英] mysql_insert_id issue in concurrency data inserting

查看:48
本文介绍了并发数据插入中的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问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆