Menu

MariaDB UUID() Function

Updated on

UUID() returns a version 1 UUID as a 36-character string in the form aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee. It has no parameters.

UUID()

How MariaDB generates the value

The UUIDv1 value combines a timestamp, a clock sequence, and a node value. MariaDB uses a network interface MAC address as the node value on FreeBSD and Linux. On other operating systems, it uses a randomly generated 48-bit value, so node-based uniqueness cannot be guaranteed; collisions should still be very unlikely.

Because UUIDv1 contains time and may contain host information, do not treat it as a secret or an authentication token. Statements using UUID() are not safe for statement-based replication; use row-based logging for statements that depend on generated UUID values.

Example

Generate one UUID:

SELECT UUID();

Example result:

+--------------------------------------+
| UUID()                               |
+--------------------------------------+
| cd41294a-afb0-11df-bc9b-00241dd75637 |
+--------------------------------------+

MariaDB 11.7 and later also provide UUID_v4() for random UUIDs and UUID_v7() for time-ordered UUIDs. UUIDv1 values are not sorted chronologically by their string representation.

For storing UUID values, see the MariaDB UUID data type. For the short 64-bit identifier, see UUID_SHORT().