Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 16:18:13
Original
1275 people have browsed it

重点是这句,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之后,再继续,这样就保证了在并发的情况下,不同的进程不会取到相同的值。 

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!