惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
T
Threatpost
C
CERT Recently Published Vulnerability Notes
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
Project Zero
Project Zero
H
Heimdal Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Know Your Adversary
Know Your Adversary
Google Online Security Blog
Google Online Security Blog
W
WeLiveSecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Schneier on Security
Schneier on Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
News | PayPal Newsroom
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
L
LINUX DO - 热门话题
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
V
Vulnerabilities – Threatpost
Hacker News: Ask HN
Hacker News: Ask HN
S
Securelist
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
NISL@THU
NISL@THU
N
News and Events Feed by Topic
S
Security Affairs
The Last Watchdog
The Last Watchdog
T
Tor Project blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
C
Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
LINUX DO - 最新话题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tenable Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security

博客园 - 唯一浩哥

2026 年,macbook air 2015 升级硬盘注意事项 Java集合系列-HashSet Java基础系列-单例的7种写法 Java基础系列-Lambda Java基础系列-SPI你认识吗 Java基础系列-时间日期API Java基础系列-RandomAccess Java基础系列-Optional 那些字段适不适合建索引? Spring知识点 Java基础系列-浅拷贝和深拷贝 前端-javascript知识点 前端-jquery知识点 Java基础系列-substring的原理 - 唯一浩哥 - 博客园 Java设计模式之《抽象工厂模式》及使用场景 - 唯一浩哥 - 博客园 Java基础系列-Enum深入解析 - 唯一浩哥 - 博客园 Java基础系列-Collector和Collectors - 唯一浩哥 - 博客园 Java基础系列-Stream - 唯一浩哥 - 博客园 Java并发编程系列-AbstractQueuedSynchronizer - 唯一浩哥 - 博客园
Mysql笔记
唯一浩哥 · 2020-08-07 · via 博客园 - 唯一浩哥

1. for update悲观锁

Mysql中使用Select ... for update操作,会锁表或者锁行,当查询条件中有明确指定主键的时候会锁行,否则会锁表(有主键但不明确的情况下任然是锁表),这种锁只有在所属事务提交后才会释放。

注意:
1.FOR UPDATE仅适用于InnoDB,且必须在事务处理模块(BEGIN/COMMIT)中才能生效
2.Myisam 只支持表级锁,InnerDB支持行级锁 添加了(行级锁/表级锁)锁的数据不能被其它事务再锁定,也不被其它事务修改。是表级锁时,不管是否查询到记录,都会锁定表。

2. 查找数据是否存在

SELECT 1 FROM table WHERE a = 1 AND b = 2 LIMIT 1
Integer exist = xxDao.existXxxxByXxx(params);
if ( exist != NULL ) {
  //当存在时,执行这里的代码
} else {
  //当不存在时,执行这里的代码
}