This lock is application level and used between different mysql sessions. It is just a name lock, and has no direct relationship with the tables, rows, and fields you understand. The specific lock is completely left to the application. It is an exclusive lock, which means that whichever session holds the lock, other sessions will fail when trying to get the lock.
For example, if you want to lock a row of record A, then you create a lock in the current sessionget_lock("record A", 10)。此时其他所有会话依然可以随便访问和修改record A,除非他们显式的也调用get_lock("record A", 10).
That is to say, it is entirely up to your application to decide whether to check the lock or not. If you want to lock, make all sessions explicitly callget_lock("record A", 10),那明显只有一个会话能成功。其他会话只有等超时或者持有锁的会话调用release_lockwhen accessing record A before you can get the lock again
Similarly, if you want to lock a field column A, then create a lock as aboveget_lock("column A", 10). In short, it is up to the application to decide whether to take the lock or not, and the database only provides this mechanism. To see if everyone grabs the same lock, it is purely based on the fact that the string of the first parameter lock name is different, so the best practice is to add the table name and database name in front of the lock name to avoid accidental injuries
This lock is application level and used between different mysql sessions. It is just a name lock, and has no direct relationship with the tables, rows, and fields you understand. The specific lock is completely left to the application. It is an exclusive lock, which means that whichever session holds the lock, other sessions will fail when trying to get the lock.
For example, if you want to lock a row of record A, then you create a lock in the current session
get_lock("record A", 10)
。此时其他所有会话依然可以随便访问和修改record A,除非他们显式的也调用get_lock("record A", 10)
.That is to say, it is entirely up to your application to decide whether to check the lock or not. If you want to lock, make all sessions explicitly call
get_lock("record A", 10)
,那明显只有一个会话能成功。其他会话只有等超时或者持有锁的会话调用release_lock
when accessing record A before you can get the lock againSimilarly, if you want to lock a field column A, then create a lock as above
get_lock("column A", 10)
. In short, it is up to the application to decide whether to take the lock or not, and the database only provides this mechanism. To see if everyone grabs the same lock, it is purely based on the fact that the string of the first parameter lock name is different, so the best practice is to add the table name and database name in front of the lock name to avoid accidental injuries