Shared locks and exclusive locks
First of all: database add, delete and change operations by default will add exclusive lock, and query will not add any lock.
-
A Shared lock
If a shared lock is added to a resource, the resource can be read by itself or by others. However, the shared lock cannot be modified. To change, you must wait until all shared locks have been released. The syntax is select * from table lock in share mode
-
Exclusive lock
Add exclusive lock to a resource, you can add, delete, change and check, others can not carry out any operation. The syntax is select * from table for update
Mysql shared lock, exclusive lock, pessimistic lock, optimistic lock and their usage scenarios