Use Case
UUID
A BINARY(16) column in MySQL stores 16 bytes of binary data, typically used to store UUIDs in binary form (instead of as strings like '550e8400-e29b-41d4-a716-446655440000'), which saves space and improves performance.
Here are some example BINARY(16) values, shown in hex format (what we'll see if we run HEX(column)):
550E8400E29B41D4A716446655440000
A UUID stored as binary
00000000000000000000000000000001
Just 16 bytes ending in 01
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
All bits set to 1
AABBCCDDEEFF00112233445566778899
Random sample
0102030405060708090A0B0C0D0E0F10
Sequential bytes
How to Insert into a BINARY(16) Column
CREATE TABLE sample_binary (
id BINARY(16)
);1. Using UNHEX() with a hex string:
INSERT INTO sample_binary (id) VALUES (UNHEX('550E8400E29B41D4A716446655440000'));2. Using a UUID directly:
Syntax for WHERE with hex value
Reading from a BINARY(16) Column
Using Concatenation
To read and convert back to UUID format:
Using BIN_TO_UUID() (MySQL 8.0.13+ only):
Output:0190de6c-bb16-74b8-80c5-f0a552bea151(properly formatted UUID)
Why Use BINARY(16) for UUIDs?
CHAR(36)
36 B
36 B
Readable
Simplicity
BINARY(16)
16 B
16 B
Binary
Performance, Index
Use BINARY(16) for performance; use CHAR(36) only if readability in the DB itself is critical.
Last updated