GUID Database Performance & Indexing Guide
Complete guide to GUID database performance, B-tree index behavior, fragmentation, storage optimization and database-specific considerations.
Generate UUID values in MySQL with UUID(), validate text with IS_UUID(), and store compact binary values with UUID_TO_BIN() and BIN_TO_UUID().
UUID() generates UUID v1 values. If you need UUID v4 or UUID v7 semantics, generate them in the application layer and store them in MySQL.SELECT UUID() AS uuid_value;According to the MySQL reference manual, UUID() returns a UUID version 1 value.
CREATE TABLE orders (
id BINARY(16) PRIMARY KEY,
description VARCHAR(200) NOT NULL
);
INSERT INTO orders (id, description)
VALUES (UUID_TO_BIN(UUID()), 'first order');
SELECT BIN_TO_UUID(id) AS id, description
FROM orders;Use BINARY(16) for compact storage. UUID_TO_BIN() and BIN_TO_UUID() handle the string-to-binary round trip.
UUID() returns UUID v1 values.UUID_TO_BIN() and BIN_TO_UUID() are the standard conversion helpers.UUID_TO_BIN(uuid, 1) only helps with time-part swapping for UUID v1 layouts.BINARY(16) instead of CHAR(36) when you care about storage and index size.UUID(), which returns UUID v1 values.BINARY(16) is smaller and indexes better than storing CHAR(36) or VARCHAR(36) UUID strings.These articles expand on related concepts, formats and practical considerations.