MariaDB UUID_v4() Function
UUID_v4() generates a version 4 UUID using random numbers. The function is available in MariaDB 11.7 and later and takes no arguments.
Syntax
UUID_v4()
The function returns a 128-bit UUID as a 36-character UTF-8 string in the standard hyphenated format:
SELECT UUID_v4();
Example result:
+--------------------------------------+
| UUID_v4() |
+--------------------------------------+
| a2443495-1b94-415b-b6fa-fe8e79ba4812 |
+--------------------------------------+You can store the result in MariaDB’s UUID data type, available from MariaDB 10.7:
CREATE TABLE request_log (
request_id UUID PRIMARY KEY,
operation VARCHAR(64) NOT NULL
);
INSERT INTO request_log (request_id, operation)
VALUES (UUID_v4(), 'create');
UUID_v4() values are intended to be unique, but MariaDB does not guarantee that they are unpredictable or unguessable. Do not use this function to generate secrets or authentication tokens. Statements using UUID_v4() are not safe for statement-based replication.
For time-ordered values, see UUID_v7(). For version 1 UUIDs, see UUID().
See MariaDB’s official UUID_v4() documentation.