How MariaDB UUID() Generates Version 1 UUIDs
Learn how MariaDB UUID() generates version 1 identifiers, what their time and node fields mean, and how UUIDv1 differs from UUIDv4 and UUIDv7.
On this page
MariaDB UUID() generates a version 1 UUID. It is a 128-bit value displayed as a 36-character string in the format 8-4-4-4-12 hexadecimal digits. Unlike a random UUIDv4, a UUIDv1 combines a timestamp, a clock sequence, and a node value.
Generate a UUIDv1
Call UUID() with no arguments:
SELECT UUID();
For example, a result may look like this:
+--------------------------------------+
| UUID() |
+--------------------------------------+
| cd41294a-afb0-11df-bc9b-00241dd75637 |
+--------------------------------------+The 1 at the start of the third group identifies this as a UUIDv1. Each call normally returns a different value, but a UUID algorithm is not a uniqueness constraint; use a PRIMARY KEY or UNIQUE constraint if the table must reject duplicates.
What the UUIDv1 fields contain
- The first three groups encode parts of a timestamp.
- The fourth group contains a clock sequence used to preserve uniqueness when the clock changes or moves backward.
- The final group contains a node identifier. MariaDB uses a network-interface MAC address on FreeBSD and Linux. On other operating systems, it uses a randomly generated 48-bit value.
Because UUIDv1 values include time and may include host information, they can reveal approximate creation time or information about the generating host. MariaDB also warns that UUID() values should not be relied on as unpredictable or unguessable; do not use them as authentication secrets.
UUIDv1, UUIDv4, and UUIDv7
| Function | Version | Ordering and generation |
|---|---|---|
UUID() |
v1 | Time, clock sequence, and node identifier; its text values are not chronologically ordered. |
UUID_v4() |
v4 | Random bits; available from MariaDB 11.7. |
UUID_v7() |
v7 | Time-ordered; available from MariaDB 11.7. |
Use UUIDv7 when values that sort by creation time are useful. Use UUIDv4 when random UUID values fit the application. Neither function should be treated as a secret token.
Store UUID values
MariaDB’s native UUID data type is available from MariaDB 10.7. This example uses a string column so it also works on earlier releases:
CREATE TEMPORARY TABLE events (
event_id CHAR(36) PRIMARY KEY,
event_name VARCHAR(80) NOT NULL
);
INSERT INTO events (event_id, event_name)
VALUES (UUID(), 'account_created');
Statements using UUID() are not safe for statement-based replication. For replication, use a logging format that records row changes rather than relying on the replica to generate the same UUID independently.
See MariaDB’s official UUID() documentation for implementation details. The UUID reference page also covers the function syntax and return value.