> For the complete documentation index, see [llms.txt](https://bohans.gitbook.io/ji-chu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bohans.gitbook.io/ji-chu/mysql/ji-chu-zhi-shi/shi-wu/liang-jie-duan-suo-ding-xie-yi.md).

# 两阶段锁定协议

InnoDB 使用<mark style="color:blue;">**两阶段锁定协议（two-phase locking protocol）：**</mark>**在事务执行期间，随时都可以获取锁，但锁只有在提交或回滚后才会释放，并且所有的锁会同时释放。**

{% hint style="success" %}
InnoDB 支持通过特定的语句进行显式锁定，这些语句不属于 SQL 规范：

```sql
SELECT *
FROM sakila.rental
WHERE rental_id = 1 
LOCK IN SHARE MODE;

SELECT *
FROM sakila.rental
WHERE rental_id = 1
FOR UPDATE;
```

{% endhint %}
