Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove dash of UUID generated directly on MySQL

Tags:

uuid

mysql

I generate UUID using INSERT INTO tbl1 (key, val) VALUES (UUID(), :value) directly on MySQL using PDO. I don't have any idea how to remove those - (dashes) on MySQL side, on PHP side I can simply remove it using str_replace().

like image 691
fishcracker Avatar asked Nov 18 '12 11:11

fishcracker


People also ask

Can MySQL generate UUID?

UUID() function in MySQL This function in MySQL is used to return a Universal Unique Identifier (UUID) generated according to RFC 4122, “A Universally Unique Identifier (UUID) URN Namespace”. It is designed as a number that is universally unique.

Can MySQL use UUID as primary key?

The following are the advantages of using UUID for a primary key: UUID values in MySQL are unique across tables, databases, and servers. It allows us to merge rows from distributed/different databases across servers. UUID values do not provide information about our data, which means it is hard to guess.

Does MySQL support GUID?

MySQL does not yet support setting a column's default value using a function (at least not yet as of version 5.6) but you can use a trigger instead. This post shows how to set a column to a UUID/GUID by default in MySQL using a trigger.


1 Answers

REPLACE(UUID(),'-','')

You don't need the UNHEX, just simply replace the hyphens.

like image 196
Alan Fullmer Avatar answered Sep 25 '22 21:09

Alan Fullmer