How to Generate UUIDs in MariaDB

Generate UUIDs in MariaDB with UUID() for UUID v1, and use UUID_v4() or UUID_v7() on MariaDB 11.7 and newer when you need random or time-ordered values.

Recommendation: on MariaDB 11.7 and newer, prefer UUID_v7() for append-heavy tables and UUID_v4() when you need random identifiers without time ordering.

How to generate UUID v1 in MariaDB

SELECT UUID() AS uuid_v1_value;

MariaDB documents UUID() as a UUID v1 generator.

How to generate UUID v4 and UUID v7 in MariaDB

SELECT UUID_v4() AS uuid_v4_value,
       UUID_v7() AS uuid_v7_value;

UUID_v4() and UUID_v7() are available from MariaDB 11.7.

How to store UUIDs efficiently in MariaDB

CREATE TABLE events (
    id BINARY(16) PRIMARY KEY,
    event_name VARCHAR(100) NOT NULL
);

INSERT INTO events (id, event_name)
VALUES (UUID_TO_BIN(UUID_v7()), 'user.created');

SELECT BIN_TO_UUID(id) AS id, event_name
FROM events;

Native support notes

  • UUID() generates UUID v1 values.
  • UUID_v4() and UUID_v7() are available from MariaDB 11.7.
  • UUID_TO_BIN() and BIN_TO_UUID() help with compact binary storage.
  • MariaDB and MySQL are not interchangeable here because their native UUID generation capabilities differ.

Practical notes

  • Use UUID v7 for better insertion locality when your MariaDB version supports it.
  • Keep UUID values in BINARY(16) if you care about index size and storage overhead.
  • Read database performance guidance before choosing a primary key strategy.

Frequently Asked Questions

Yes, from MariaDB 11.7 onward with UUID_v7().

They both expose UUID() for UUID v1 generation, but MariaDB also adds native UUID_v4() and UUID_v7() support from version 11.7.

Learn more

These articles expand on related concepts, formats and practical considerations.

By using this site, you agree to our Privacy Policy and Terms of Service. You are not permitted to use the GUIDs (also known as UUIDs) generated by this site or use any other content, services and information available if you do not agree to these terms.
Disclaimer: All information is provided for general educational and technical reference only. While we aim to keep the content accurate, current and aligned with published standards, no guarantees are made regarding completeness, correctness or suitability for any specific use case.
GUID specifications, best practices, security guidance, database behavior and ecosystem conventions (including cloud platforms and identifier formats) may change over time or differ by implementation. Examples, recommendations and comparisons are illustrative and may not apply universally.
This content should not be considered legal, security, compliance or architectural advice. Before making critical design, security or production decisions, always consult the latest official standards and vendor-specific documentation.
Always evaluate behavior in your own environment.
Standards Compliance: The GUIDs generated by this site conform to RFC 4122 and RFC 9562 specifications whenever possible, using cryptographically secure random number generation.