MySQL UUID to BINARY(16) Converter
Storing UUIDs in a BINARY(16) column instead of CHAR(36) makes MySQL keys less than half the size, but the values become hard to read and easy to get wrong. A query returns 0x11F1D3248C1653AD... and you need the UUID behind it. A lookup finds nothing because the column was written with UUID_TO_BIN(uuid, 1) and the query used swap flag 0. An insert fails with Data too long because the 36-character string went in without conversion. Paste UUIDs or binary values, one per line. Accepted forms are UUID strings in any of the three forms IS_UUID() accepts (hyphenated, 32 hex digits, or in braces), 0x... and X'...' hex literals, HEX() output and Base64 of 16 bytes. You get the results of UUID_TO_BIN with swap flag 0 and 1 for each UUID, and BIN_TO_UUID both ways for each binary value. The tool also shows the version and variant and decodes timestamps of version 1, 6 and 7 UUIDs to 100-nanosecond precision. For binary values it tells you which swap flag the bytes were most likely written with. Invalid strings get the exact ERROR 1411 message MySQL would return and the reason. The conversion rules were checked against MySQL 8.4.11 (7,000 generated values, including 1,965 invalid strings) and the timestamps against PostgreSQL 18's uuid_extract_timestamp(). Everything runs in your browser.
Do more than mysql uuid to binary(16) converter — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Paste UUID strings or BINARY(16) values (0x... from the mysql client, HEX(id) output or Base64 from your application), one per line.
- Choose how to read bare 32-digit hex and which swap flag your schema uses for the generated SQL, then click Convert.
- Read the converted values, the decoded version and timestamp and the swap flag verdict, then copy the SQL to query or migrate the column.
Frequently asked questions
What does the swap_flag in UUID_TO_BIN and BIN_TO_UUID do?
With swap_flag 1, UUID_TO_BIN moves the time-high part of a version 1 UUID (bytes 7-8) to the front and the time-low part (bytes 1-4) to the end of the timestamp, so 6ccd780c-baba-1026-... becomes 0x1026BABA6CCD780C.... MySQL's UUID() returns version 1 UUIDs whose first 8 hex digits change fastest, so without the swap new keys land all over the InnoDB primary key index. With the swap they arrive in roughly increasing order, which keeps inserts fast. You must read the values back with the same flag: BIN_TO_UUID(id, 1). The flag does not help version 4 or version 7 UUIDs, which should be stored with swap_flag 0.
Why does BIN_TO_UUID return a different UUID than the one I inserted?
The column was written with one swap flag and read with the other. UUID_TO_BIN(u, 1) followed by BIN_TO_UUID(b) (flag 0) returns a valid-looking but different UUID, and WHERE id = UUID_TO_BIN(u) finds no rows. Paste the binary value into this tool: it shows both readings and which one has a sensible version and timestamp. Then use that flag consistently in every query, default value, generated column and foreign key. Values written by application code (for example Java's UUID to bytes or Python's uuid.bytes) are in plain order, which matches swap_flag 0.
Why do I get ERROR 1411 Incorrect string value for function uuid_to_bin?
UUID_TO_BIN only accepts the three forms that IS_UUID() returns 1 for: 8-4-4-4-12 hex digits with hyphens, 32 hex digits without hyphens, or the hyphenated form in braces. Leading or trailing spaces, a missing or extra digit, a misplaced hyphen, braces around the 32-digit form and non-hex letters all raise ERROR 1411. Run SELECT v FROM t WHERE IS_UUID(v) = 0 to find bad rows before converting a column, and TRIM() values that came from CSV imports. In Chat2DB you can run these checks and browse BINARY(16) keys as readable UUIDs: download it at chat2db.ai/download or open app.chat2db.ai.
