UUID()
Function Description
UUID() returns the UUID (Universally Unique IDentifier) generated based on RFC 4122.
UUID is the only number in the world in space and time. Even if a UUID call is performed on two unconnected, independently running devices, two different values are expected to be generated.
Info
Although the UUID() values are unique, they are not unguessable or unpredictable. If unpredictability is required, the UUID value should be generated in other ways.
UUID() returns a value of version 1 UUID that conforms to the RFC 4122 standard, which is a 128-bit number. It indicates that it is a utf8mb3 string composed of five hexadecimal digits, namely aaaaaaa-bbbb-cccc-ddd-eeeeeeeeeeeeee. The format is explained as follows:
-
The first three numbers are generated from the low, medium and high parts of the timestamp. The high part also includes the UUID version number.
-
The fourth number retains time uniqueness in case the timestamp value loses singularity (e.g., daylight saving time).
-
The fifth number is the IEEE 802 node number of spatial uniqueness. If the latter is not available (e.g., because the host device does not have an Ethernet card, or does not know how to find the hardware address of the interface on the host operating system), then a random number is replaced. In this case, the uniqueness of the space cannot be guaranteed. However, the probability of the fifth digit overlap is very low.
UUID is both a data type and a function. For more information about UUID data types, see UUID Type.
Function Syntax
> UUID()
Example
drop table if exists t1;
create table t1(a INT, b float);
insert into t1 values(12124, -4213.413), (12124, -42413.409);
mysql> SELECT length(uuid()) FROM t1;
+---------------------+
| length(uuid()) |
+---------------------+
| 36 |
| 36 |
+---------------------+
2 rows in set (0.00 sec)
mysql> SELECT UUID();
+---------------------------------------------+
| uuid() |
+---------------------------------------------+
|b293b688-70a7-11ed-a25a-5ad2460dea50 |
+---------------------------------------------+
1 row in set (0.00 sec)
limit
UUID() does not support optional parameters for the time being, that is, UUID([number]) is not supported.