并发数据插入中的mysql_insert_id问题

mysql_insert_id issue in concurrency data inserting(并发数据插入中的mysql_insert_id问题)
本文介绍了并发数据插入中的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问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)