当前位置:网站首页>内置函数锁相关
内置函数锁相关
2022-07-27 17:40:00 【华为云】
11.9 加锁与解锁函数
MySQL中提供了对数据进行加锁和解锁的函数,这些函数包括GET_LOCK(value,timeout)、RELEASE_LOCK(value)、IS_FREE_LOCK(value)和IS_USED_LOCK(value)函数。
11.9.1 GET_LOCK(value,timeout)函数
GET_LOCK(value,timeout)函数使用字符串value给定的名字获取锁,持续timeout秒。如果成功获取锁,则返回1,如果获取锁超时,则返回0,如果发生错误,则返回NULL。使用GET_LOCK(value,timeout)函数获取的锁,当执行RELEASE_LOCK(value)或断开数据库连接(包括正常断开和非正常断开),锁都会被解除。使用示例如下:
mysql> SELECT GET_LOCK('mysql',1000);+------------------------+| GET_LOCK('mysql',1000) |+------------------------+| 1 |+------------------------+1 row in set (0.00 sec)获得一个名称为mysql,持续时间为1000s的锁。
11.9.2 RELEASE_LOCK(value)函数
RELEASE_LOCK(value)函数将以value命名的锁解除。如果解除成功,则返回1,如果线程还没有创建锁,则返回0,如果以value命名的锁不存在,则返回NULL。
mysql> SELECT RELEASE_LOCK('mysql');+-----------------------+| RELEASE_LOCK('mysql') |+-----------------------+| 1 |+-----------------------+1 row in set (0.10 sec)注意:锁不存在包括两种情况。
·从未被GET_LOCK(value,timeout)函数获取过。
·锁已经被调用RELEASE_LOCK(value)函数释放过。
11.9.3 IS_FREE_LOCK(value)函数
IS_FREE_LOCK(value)函数判断以value命名的锁是否可以被使用。如果可以被使用,则返回1,如果不能使用,也就是说正在被使用,则返回0,如果发生错误,则返回NULL。使用示例如下:
mysql> SELECT IS_FREE_LOCK('mysql');+-----------------------+| IS_FREE_LOCK('mysql') |+-----------------------+| 1 |+-----------------------+1 row in set (0.00 sec)11.9.4 IS_USED_LOCK(value)函数
IS_USED_LOCK(value)函数判断以value命名的锁是否正在被使用,如果正在被使用,则返回使用该锁的数据库连接ID,否则返回NULL。使用示例如下:
mysql> SELECT IS_USED_LOCK('mysql'), IS_USED_LOCK('test');+-----------------------+----------------------+| IS_USED_LOCK('mysql') | IS_USED_LOCK('test') |+-----------------------+----------------------+| NULL | 8 |+-----------------------+----------------------+1 row in set (0.00 sec)边栏推荐
猜你喜欢

Capacitance in series and in parallel and capacitance in series and balance resistance

Chemical giant BASF & Pasqual: using quantum neural network to optimize weather forecast

PMP每日一练 | 考试不迷路-7.27(包含敏捷+多选)

Software configuration | tigervnc download, installation and configuration

2022爱分析·智慧社区厂商全景报告 厂商征集

An in-depth understanding of crystal oscillation circuit derived from xtalin pin and xtalout pin of single chip microcomputer

Broadcastreceiver (broadcast)

长安链数据存储源码分析

Gesturedetector (gesture recognition)

mysql数据库中的数据如何加密呢?mysql8.0自带新特性
随机推荐
[pytorch series] detailed explanation of the torchvision image processing library of pytorch
[论文阅读] Rich Feature Hierarchies for Accurate Object Detection and Semantic Segmentation
剑指 Offer 25. 合并两个排序的链表
疫情下我离职一年,收入增长了10倍
Gestureoverlayview (gesture recognition 2)
mysql函数汇总之系统信息函数
C171:考勤系统
ECU software and hardware architecture
第2章 入门
[openbmc series] 4. Start the process and use qume to simulate ast2600 EVB
统一建模语言 (UML) 规范
Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.
Sharepreference (storage)
黑客入门教程(非常详细)从零基础入门到精通,看完这一篇就够了。
No experts! Growth secrets for junior and intermediate programmers and "quasi programmers" who are still practicing in Universities
Unified Modeling Language (UML) specification
Common errors reported by pytorch
[C #] positive sequence, reverse sequence, maximum value, minimum value and average value
Container summary
中国业务型CDP白皮书 | 爱分析报告