Skip to main content

Lock

1. What locks are there in MySQL?

  • Locks can be categorized into three types: global locks, table-level locks, and row-level locks.

Global Lock

  1. Using the FLUSH TABLES WITH READ LOCK statement puts the entire database in a read-only state
  2. During this time, operations such as inserts, updates, deletes, or table structure modifications by other threads are blocked.
  3. Mainly used for full database logical backups to ensure data consistencies in the backup file.

Table-Level Lock

  1. Table Lock
  2. Metadata Lock (MDL)
  3. Intention Lock

Row-Level Lock

  1. Record Lock
  2. Gap Lock
  3. Next-Key Lock