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

  1. Paste UUID strings or BINARY(16) values (0x... from the mysql client, HEX(id) output or Base64 from your application), one per line.
  2. Choose how to read bare 32-digit hex and which swap flag your schema uses for the generated SQL, then click Convert.
  3. 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.

More free SQL tools

SQL Formatter & Beautifier
Format and beautify SQL queries online with dialect-aware indentation and keyword casing.
SQL Validator & Syntax Checker
Check SQL syntax online for MySQL, PostgreSQL and more, with clear error messages.
SQL Minifier
Minify SQL by stripping comments and collapsing whitespace into a single line.
MySQL to PostgreSQL Converter
Convert MySQL DDL and queries to PostgreSQL syntax with a best-effort dialect translator.
CSV to SQL Converter
Turn CSV, TSV or pasted Excel data into SQL INSERT statements.
JSON to SQL Converter
Convert a JSON array of objects into SQL INSERT statements.
SQL IN Clause Generator
Paste a list of values and get a ready-to-use SQL IN (...) clause.
SQL Escape & Unescape
Escape single quotes and special characters for safe SQL string literals.
JDBC Connection String Builder
Build JDBC URLs for MySQL, PostgreSQL, SQL Server, Oracle, MariaDB and ClickHouse.
SQL Cheat Sheet
A practical SQL reference: joins, aggregation, window functions, DDL and dialect differences.
UUID Generator (v4 & v7)
Generate UUID v4 and time-ordered UUID v7 in bulk, as plain text, JSON, CSV or SQL.
Cron Expression Generator & Validator
Build and validate cron expressions with plain-English explanations and next run times.
PostgreSQL EXPLAIN Plan Visualizer
Turn EXPLAIN ANALYZE output into a readable plan tree with timings and tuning warnings.
PgBouncer Config Generator
Generate pgbouncer.ini and size connection pools from your app instances and CPU cores.
PostgreSQL Partition Table Generator
Generate RANGE, LIST and HASH partitioning DDL with child partitions and maintenance SQL.
pg_dump Command Generator
Build pg_dump and pg_restore commands with format, filter and parallel job options.
mysqldump Command Generator
Build mysqldump backup commands with scope, options and a matching restore command.
SQL Test Data Generator
Generate realistic fake rows as SQL INSERT statements, CSV or JSON, right in your browser.
PostgreSQL Config Calculator
Calculate tuned postgresql.conf settings from your RAM, CPU cores, connections and workload.
SQL DDL to Code Generator
Convert CREATE TABLE statements into TypeScript, Prisma, Drizzle, Go, JPA or SQLAlchemy models.
SQL Window Function Generator
Build ROW_NUMBER, RANK, LAG, LEAD and running-total OVER() clauses with PARTITION BY and frames.
Docker Compose PostgreSQL Generator
Generate a docker-compose.yml for PostgreSQL with volumes, healthchecks, init scripts and pgAdmin.
PostgreSQL Replication Config Generator
Generate streaming and logical replication config: postgresql.conf, pg_hba.conf, slots and pg_basebackup.
SQL Injection Checker
Scan code for SQL injection risks and rewrite unsafe queries with bound parameters.
SQL to ER Diagram Generator
Paste CREATE TABLE DDL and get an entity relationship diagram plus Mermaid erDiagram code.
Postgres Connection String Generator
Build PostgreSQL connection strings: libpq URI, DSN, JDBC, psycopg, SQLAlchemy, Npgsql and .env.
Postgres GRANT Statement Generator
Generate PostgreSQL GRANT, ALTER DEFAULT PRIVILEGES and REVOKE scripts for read-only or read-write roles.
Postgres COPY Command Generator
Build PostgreSQL COPY and psql \copy commands to import or export CSV with HEADER, DELIMITER, NULL and WHERE options.
Postgres CREATE INDEX Generator
Generate PostgreSQL CREATE INDEX statements: B-tree, GIN, GiST, BRIN, UNIQUE, CONCURRENTLY, partial WHERE, INCLUDE and expression indexes.
Postgres TO_CHAR Date Format Builder
Build PostgreSQL TO_CHAR date format patterns with live preview, presets and generated TO_CHAR / TO_TIMESTAMP statements.
Postgres FDW Setup Generator
Generate postgres_fdw CREATE SERVER, USER MAPPING and IMPORT FOREIGN SCHEMA SQL for querying a remote Postgres database.
Postgres EXCLUDE Constraint Generator
Generate PostgreSQL EXCLUDE constraint SQL: GiST/SP-GiST operators, btree_gist columns, partial WHERE and overlap-check verification.
pgvector Index & Schema Generator
Generate pgvector SQL: vector/halfvec columns, HNSW or IVFFlat indexes, tuned parameters and the matching nearest-neighbour query.
Postgres ALTER COLUMN TYPE Generator
Generate ALTER TABLE ALTER COLUMN TYPE SQL with the right USING cast, a table-rewrite verdict and a batched zero-downtime migration.
Postgres UPSERT Generator
Build INSERT ... ON CONFLICT DO UPDATE/DO NOTHING statements, the MERGE equivalent and the unique index they need.
pg_hba.conf Generator
Generate PostgreSQL client authentication rules with the right connection type, CIDR and auth method.
Postgres Trigger Generator
Generate CREATE TRIGGER SQL and plpgsql trigger functions: updated_at touch, JSONB audit log, operation guards and TG_OP skeletons.
Postgres VACUUM Command Generator
Build VACUUM / VACUUM FULL / ANALYZE commands with the right options, plus monitoring SQL and per-table autovacuum tuning.
SQL Pivot Generator (Rows to Columns)
Generate pivot queries with FILTER or CASE WHEN aggregates, the PostgreSQL crosstab() version and the reverse unpivot.
Epoch & Unix Timestamp Converter
Convert epoch to date and back with auto unit detection, plus to_timestamp and extract(epoch) SQL snippets.
pg_restore Command Generator
Build pg_restore or psql restore commands from a Postgres dump: archive format, parallel jobs, clean, no-owner and single-transaction options.
Postgres JSONB Query Builder
Generate JSONB queries from a nested path and operator, with the matching GIN or expression index and a JSONB cookbook.
SQL Schema Diff & Migration Generator
Compare two SQL schemas and generate the ALTER TABLE up and down migration, with lock and rewrite warnings.
Postgres Table Size Estimator
Estimate table and index size from your columns and row count, including tuple header, alignment padding and column-order savings.
Postgres Full Text Search Generator
Generate tsvector columns, GIN indexes, weighted ranking and ts_headline queries for PostgreSQL full text search.
Levenshtein Distance Calculator
Compute edit distance between two strings with the full DP matrix, edit path and matching Postgres fuzzy search SQL.
SQL Linter & Style Checker
Lint SQL for correctness traps, non-sargable predicates and style issues in your browser.
Database Normalization Analyzer
Find candidate keys and 1NF/2NF/3NF/BCNF violations, then get a lossless decomposition.
Connection Pool Size Calculator
Size your database connection pool from cores, latency and instances, with HikariCP, pgxpool, node-pg, SQLAlchemy and PgBouncer config.
PostgreSQL Error Code Lookup
Look up any SQLSTATE code or paste an error message to get the cause, the fix and how to catch it in your driver.
Postgres Autovacuum Calculator
Work out when autovacuum fires on a table, how much bloat builds up first, and generate per-table ALTER TABLE tuning.
SQL to MongoDB Query Converter
Convert a SQL SELECT into a MongoDB find() call or aggregation pipeline, with $lookup, $group, $match and $sort mapping.
pgloader Config Generator
Build a pgloader .load file to migrate MySQL, SQL Server, SQLite or CSV into PostgreSQL, with cast rules, table filters and verification SQL.
Postgres Upgrade Planner
Compare pg_upgrade, dump/restore and logical replication for a major version upgrade, with downtime estimates, commands and breaking changes.
SQL Join Visualizer
See INNER, LEFT, RIGHT, FULL, CROSS and anti joins run on real sample rows, with the SQL.
SCD Type 2 SQL Generator
Generate slowly changing dimension Type 2 DDL and load SQL for Postgres, Snowflake and BigQuery.
Postgres RLS Policy Generator
Generate PostgreSQL row level security policies for multi-tenant, per-user or role-based access.
Postgres Data Masking Generator
Build masked views, anonymization UPDATEs or PostgreSQL Anonymizer labels for sensitive columns.
Online SQL Playground
Run SQL in your browser against a sample SQLite database, with 10 checked practice exercises.
SQL CASE WHEN Generator
Build searched or simple CASE expressions with full queries and IF/IIF/DECODE equivalents per dialect.
SQL Set Operations Visualizer
See UNION, UNION ALL, INTERSECT and EXCEPT run on real rows, with counts and SQL per dialect.
Postgres Enum Type Generator
Generate CREATE TYPE, ADD VALUE, RENAME VALUE, safe value removal and enum-to-CHECK or lookup migrations.
Postgres Lock Conflict Checker
Check whether two PostgreSQL statements or LOCK TABLE modes block each other, with the conflict matrix and pg_locks queries.
Postgres Timezone Converter
Convert timestamps between IANA zones and generate AT TIME ZONE, SET timezone and date_trunc SQL with DST warnings.
Slow Query Log Analyzer
Group a MySQL or PostgreSQL slow query log by normalized query shape and rank the shapes by total time.
Postgres generate_series Builder
Build generate_series SQL for calendar tables, time buckets, gap-filled reports and test data, with a row preview.
Postgres Index Type Advisor
Pick between B-tree, Hash, GIN, GiST, SP-GiST, BRIN and HNSW for a column and query pattern, with the CREATE INDEX statement and operator class.
Postgres SERIAL to IDENTITY Converter
Convert a SERIAL or BIGSERIAL column to GENERATED AS IDENTITY with the correct setval, rollback and optional bigint widening.
Postgres DROP ROLE Helper
Generate the audit queries, REASSIGN OWNED, DROP OWNED and DROP ROLE script that clears "role cannot be dropped" errors.
pg_stat_statements Query Builder
Build version-correct Top-N pg_stat_statements queries by total time, mean time, calls, cache misses, temp spills or WAL.
AWS DMS Table Mapping Generator
Build a valid AWS DMS table-mappings.json with selection rules, schema and table renames, column removal and source row filters.
ClickHouse MergeTree Table Generator
Generate ClickHouse CREATE TABLE DDL with MergeTree engines, sorting keys, partitioning, TTL and compression codecs.
SQL Server to PostgreSQL Converter
Translate T-SQL DDL and queries to PostgreSQL: brackets, IDENTITY, NVARCHAR, TOP, GETDATE and more.
Docker Compose MySQL & MariaDB Generator
Generate docker-compose.yml for MySQL or MariaDB with volumes, healthchecks, init scripts and phpMyAdmin.
Oracle to PostgreSQL Converter
Translate Oracle DDL and SQL to PostgreSQL: VARCHAR2, NUMBER, NVL, DECODE, SYSDATE, sequences and more.
SQL Server Backup & Restore Command Generator
Generate T-SQL BACKUP and RESTORE scripts with compression, checksum, WITH MOVE, STOPAT and sqlcmd.
pgbench Command Generator
Build pgbench init and benchmark command lines for PostgreSQL load testing.
dbt schema.yml Generator
Turn a CREATE TABLE statement into a dbt schema.yml with data tests and a unit test skeleton.
DBML to SQL Converter
Convert DBML schemas to PostgreSQL or MySQL DDL, and turn existing CREATE TABLE statements back into DBML.
Liquibase Changelog Generator
Turn SQL DDL into a Liquibase changelog in XML, YAML, JSON or formatted SQL, with constraints and rollbacks.
MySQL Config Calculator
Generate a tuned my.cnf from your RAM, cores and workload, with an InnoDB memory budget check.
Debezium Connector Config Generator
Build a Debezium CDC connector config for PostgreSQL, MySQL, SQL Server, Oracle or MongoDB.
MongoDB Connection String Builder
Build or parse mongodb:// and mongodb+srv:// URIs with encoded passwords, auth and replica set options.
MySQL GRANT Statement Generator
Generate MySQL 8 CREATE USER, GRANT, role and REVOKE scripts for read-only, read-write or replication users.
SQL Server Connection String Builder
Build or parse SQL Server connection strings for ADO.NET, ODBC, JDBC, sqlcmd and SQLAlchemy with Encrypt options.
MySQL DATE_FORMAT Builder
Build MySQL DATE_FORMAT and STR_TO_DATE patterns with a live preview and every % format specifier explained.
Oracle tnsnames.ora Generator
Build or parse Oracle tnsnames.ora entries with RAC failover and TCPS, plus EZConnect, JDBC thin URLs and sqlplus.
SQL Server Date Format Converter
Every CONVERT date style code (101, 103, 112, 120, 126…) rendered live, plus a FORMAT() builder and string-to-date help.
SQL INSERT to CSV / JSON Converter
Turn INSERT statements or a mysqldump / pg_dump file into CSV, TSV, JSON or Markdown, with correct quoting and NULLs.
Oracle Date Format Builder
Live TO_CHAR preview for any Oracle date format mask (FM, TH/SP, IW, J, FF), common masks and TO_DATE string parsing.
SQL Parameter Binder
Paste a MyBatis or Hibernate log, or SQL with ?, $1 or :name placeholders, and get runnable SQL with the values filled in.
MySQL Error Code Lookup
Look up a MySQL error number, symbol or message and get the cause, a concrete fix and a code snippet to catch it in your driver.
Postgres Sequence Reset Generator
Fix "duplicate key value violates unique constraint" after imports: generate setval SQL that resets serial and identity sequences to MAX(id)+1.
SQL Data Dictionary Generator
Paste CREATE TABLE DDL and get a data dictionary with types, keys, defaults and comments as Markdown, HTML, CSV or JSON.
PostgreSQL to MySQL Converter
Convert PostgreSQL DDL and queries to MySQL: SERIAL, BOOLEAN, TIMESTAMPTZ, JSONB, UUID, ENUM types, ON CONFLICT and STRING_AGG, with warnings.
MongoDB to SQL Query Converter
Turn a MongoDB find() or aggregation pipeline into SQL for PostgreSQL, MySQL, SQL Server or SQLite, with a clause-by-clause mapping.
MySQL Partition Generator
Generate MySQL PARTITION BY RANGE, LIST, HASH or KEY DDL for date and integer columns, plus ADD, REORGANIZE and DROP PARTITION maintenance SQL.
MySQL EXPLAIN Analyzer
Paste MySQL EXPLAIN, EXPLAIN FORMAT=JSON or EXPLAIN ANALYZE output and get a plain-English breakdown with full scans, filesorts and misestimates flagged.
Postgres SCRAM-SHA-256 Password Hash Generator
Pre-hash a PostgreSQL password into a SCRAM-SHA-256 verifier in your browser and get CREATE or ALTER ROLE SQL, or verify a password against a stored hash.
SQL LIKE Pattern Tester
Test LIKE and ILIKE patterns against sample values with per-database wildcard, ESCAPE and case rules, and escape literal % and _ safely.
Postgres Bytea Converter
Convert PostgreSQL bytea values between \x hex, escape format, base64, plain hex and UTF-8 text, with encode/decode SQL.
Postgres Array Literal Builder & Parser
Build correctly quoted '{...}' array literals and ARRAY[] constructors from a list or JSON, or parse one and explain malformed array literal errors.
Postgres inet & cidr Calculator
Parse IPv4 and IPv6 inet/cidr values like PostgreSQL: network, broadcast, netmask, abbrev, containment operators and invalid cidr value errors.
Postgres Interval Converter
Convert ISO 8601 durations and Postgres interval strings to every IntervalStyle, with justify_interval, extract(epoch) and make_interval.
Postgres numeric(p,s) Precision Checker
Check values against numeric(precision, scale): see the rounded stored value, the exact numeric field overflow error and the smallest type that fits.
Postgres LSN & WAL File Calculator
Convert an LSN to its WAL file name and offset, map a WAL file back to an LSN range and compute pg_wal_lsn_diff for replication lag.
Postgres Range Type Calculator
Parse int4range, numrange, daterange and tsrange literals, see the canonical form and test @>, &&, -|-, union, intersection and difference.
MySQL Index Key Length Calculator
Check every index in a CREATE TABLE against InnoDB's 3072/767-byte limits, predict error 1071, 1170 and 1089, and get the EXPLAIN key_len.
MySQL Row Size Calculator
Check a CREATE TABLE against the 65535-byte server limit and the 8126-byte InnoDB page limit, predict error 1118 and 1074, and see which columns cost most.
Postgres Identifier Checker
See how PostgreSQL folds, truncates (63 bytes) and quotes your table and column names, spot reserved keywords, and preview auto-generated constraint names.
MySQL sql_mode Checker
See what MySQL 8 stores for a sql_mode value, what each mode does, and fix error 1231 from removed modes like NO_AUTO_CREATE_USER.
MySQL GTID Set Calculator
Compare source and replica gtid_executed: GTID_SUBTRACT, errant transactions, purged GTIDs behind error 1236, and the SQL to fix them.
pg_trgm Similarity Calculator
Compute show_trgm, similarity, word_similarity and strict_word_similarity exactly like PostgreSQL, and test % and <% thresholds.
MySQL JSON Path Tester
Run JSON paths against a document like JSON_EXTRACT and ->>, see every matched location, and get exact ERROR 3143 positions with fixes.
Deadlock Log Analyzer
Read InnoDB LATEST DETECTED DEADLOCK and PostgreSQL deadlock logs: held and waited locks, the cycle, the victim and the fix.
OtterMind
OtterMind