The uses of mysql locks: 1. When sharing the lock, other users can read it but cannot change the meter data, which only affects the user; 2. When using the exclusive lock, other users can neither read nor change it. Table data; 3. Ensure the atomicity, integrity, and consistency of data.
The purpose of mysql lock:
Simply put, it is to lock the table and prevent others from touching it
1. There are two main types of locks: shared locks and exclusive locks
When sharing a lock, others can read it but cannot change the meter data.
When locking exclusively, others can neither read nor modify table data.
Based on the above characteristics, you should know when to use a lock. If you don't want others to change the data and affect you, lock it. The lock must be released after it is no longer used, otherwise the application system will always report errors due to reading data.
2. The advantage is to ensure the atomicity, integrity and consistency of data. Only when the lock holder releases the lock can others change the data.
3. The disadvantage is that it increases system overhead and may cause lock waiting, causing abnormal database operation. These are all problems caused by abnormal use of locks.
Related learning recommendations: mysql video tutorial
The above is the detailed content of What is the use of mysql lock?. For more information, please follow other related articles on the PHP Chinese website!