Is it possible to generate a UUID version 4 (completely random) in MySQL? I would like to use it as a primary key.
Use Case
---------
- Many systems will insert to the table, some may specify a UUID when inserting, but some will not. They will generate their own UUID, then insert it later (offline insert).
- I already have systems that use MySQL, and I would prefer to stay with the same DBMS.
- I prefer UUID v4 because of its physical machine independence.
Alternatives
-------------
I could simply create a trigger that calls the
uuid
function, as outlined in https://dba.stackexchange.com/questions/57293/mysql-alter-table-to-automatically-put-in-a-uuid , but the uuid
function generates UUID v1 ids.
I could always generate the UUID externally, but I would prefer a built-in default.
This is easy to do in Postgres, and some other DBMSes, but is there a way to do it in MySQL?
Asked by Justin Howard
(181 rep)
May 2, 2016, 11:14 PM
Last activity: Feb 17, 2025, 01:07 AM
Last activity: Feb 17, 2025, 01:07 AM