GET_LOCK( )

This MySQL function attempts to get a lock on the name given in the first argument.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

GET_LOCK(string, seconds)

Explanation

This function attempts to get a lock on the name given in the first argument. The number of seconds to attempt the lock is given in the second argument. If successful, 1 is returned. If the function is unsuccessful because the attempt times out, it returns 0. If the lock fails due to an error of any kind, NULL is returned. The function RELEASE_LOCK() may be used to release a lock. It's also released when the same client issues another GET_LOCK() or when the client's connection is terminated.

Examples

SELECT GET_LOCK('my_lock', 10);

+-------------------------+
| GET_LOCK('my_lock', 10) |
+-------------------------+
|                       1 |
+-------------------------+