Home >Database >Mysql Tutorial >mysql事务特性实现并发安全的自增ID示例

mysql事务特性实现并发安全的自增ID示例

WBOY
WBOYOriginal
2016-06-07 16:18:131345browse

重点是这句,select id into oldid from maibo_auto_id where idname=idname_in for update,会给相关数据加一个独占锁定,这时候别的进程如果来读取该条记录,就会进入等待,等待这个进程commit之后,再继续,这样就保证了在并发的情况下,不同的进程不会取

重点是这句,select id into oldid from maibo_auto_id where idname=idname_in for update,会给相关数据加一个独占锁定,这时候别的进程如果来读取该条记录,就会进入等待,等待这个进程commit之后,再继续,这样就保证了在并发的情况下,不同的进程不会取到相同的值。 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn