Sponsored Advertisement

UUID Primary IDs and MySQL

This post from the MySQL Server Team is an interesting approach to handling UUIDs in MySQL. The primary takeaway is to convert the UUID to a binary data type by removing the "-" characters and performing unhex() on the UUID. Here is another post on storing UUIDs in MySQL from percona.com, emphasizing the memory savings of using the UUID-to-Binary approach.

I recently added visitor logging which I described in this post and wanted to use UUID Primary Keys. I liked the unhex() / binary approach but felt that retrieving binary values isn't as straightforward as I liked. So I simply removed the UUID "-" characters and saved the field as a char(32) data type. You could have used a binary(32) data type here, but storage requirements are essentially the same.

My IDs then look like this.

And insert statement like this.

I didn't end up saving any memory, but I think this is a cleaner approach and I can retrieve records the old fashioned way.

select * from client_info where id = '065b4ef72c7411e89af710feed849ea9';

More Like This Post