1. Concurrency control problems occur whenever more than one query modifies data at the same time

2. How to control read and write concurrently in mysql server layer and storage engine layer

If more than one process writes to the mbox file at the same time, there will be confusion at the end of the file. For example, process 1 writes several lines, and process 2 also writes several lines, and the data will be wrong. A well-designed Mbox requires a lock. For example, if process 1 locks a file, process 2 must wait for process 1 to finish before the lock is released. Concurrency is not supported and only one process can write data at a time

4. There may be problems when reading data. For example, when one process is reading data, another process wants to delete data at the same time. Shared locks are called read locks, and exclusive locks are called write locks

5. The read lock is shared and does not block other read locks. Write locks are exclusive and block other read and write locks; Reading is not mutually exclusive, reading is mutually exclusive, writing is mutually exclusive

6. The mysql database is locked all the time. When a user modifies data, other users will be blocked from accessing the data

Mysql has two types of lock granularity: lock whole table and lock row

Table lock: When a user modifies data, the write lock will be obtained, and the entire table will be locked, and other users cannot read and write,myisam

Row lock: When a user modifies a few rows of data, a write lock will be obtained. At this time, only those rows are locked, and other users cannot read and write those rows. Other rows are not affected, but admin locks consume resources, innoDB

8. Run the unlock tables command to unlock all rows lock tables table name read or write

Test read/write read exclusivity

1. Add read locks

! [](https://picb.zhimg.com/80/v2-26e8bdf701a39b923658b8167993ee1c_720w.png)

Read data is not affected, write data will be blocked

! [](https://pic3.zhimg.com/80/v2-37831f5411fb9763319e5684f41f8c93_720w.png)

2. Add write locks

! [](https://pic4.zhimg.com/80/v2-15e1ab11323de7e84677245c086fe8d8_720w.png)

Both read and write are blocked

! [](https://pic2.zhimg.com/80/v2-b09dcec683062c939b123f0b68324e9c_720w.png)

I hope the above content can help you. Many PHPer will encounter some problems and bottlenecks when they are advanced, and they have no sense of direction when writing too many business codes. I have sorted out some information, including but not limited to: Distributed architecture, high scalability, high performance, high concurrency, server performance tuning, TP6, Laravel, Redis, Swoft, Kafka, Mysql optimization, shell scripting, Docker, microservices, Nginx, etc. Many knowledge points can be free to share with you