UUID Primary IDs and MySQL
source link: https://nixmash.com/mysql/uuid-primary-ids-and-mysql/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
UUID Primary IDs and MySQL – NixMashSkip to content
WordPress Site Management for Small Business
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';
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK