MySQL tutorial: UUID [EN]
top of page
CerebroSQL

MySQL: 

UUID

Syntax:
UUID()

Returns a Universal Unique Identifier (UUID) generated according to RFC
4122, "A Universally Unique IDentifier (UUID) URN Namespace"
(http://www.ietf.org/rfc/rfc4122.txt).

A UUID is designed as a number that is globally unique in space and
time. Two calls to UUID() are expected to generate two different
values, even if these calls are performed on two separate devices not
connected to each other.

*Warning*:

Although UUID() values are intended to be unique, they are not
necessarily unguessable or unpredictable. If unpredictability is
required, UUID values should be generated some other way.

UUID() returns a value that conforms to UUID version 1 as described in
RFC 4122. The value is a 128-bit number represented as a utf8 string of
five hexadecimal numbers in aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
format:

o The first three numbers are generated from the low, middle, and high
parts of a timestamp. The high part also includes the UUID version
number.

o The fourth number preserves temporal uniqueness in case the timestamp
value loses monotonicity (for example, due to daylight saving time).

o The fifth number is an IEEE 802 node number that provides spatial
uniqueness. A random number is substituted if the latter is not
available (for example, because the host device has no Ethernet card,
or it is unknown how to find the hardware address of an interface on
the host operating system). In this case, spatial uniqueness cannot
be guaranteed. Nevertheless, a collision should have very low
probability.

The MAC address of an interface is taken into account only on
FreeBSD, Linux, and Windows. On other operating systems, MySQL uses a
randomly generated 48-bit number.

URL: https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html

Example

mysql> SELECT UUID();
-> '6ccd780c-baba-1026-9564-5b8c656024db'

bottom of page