存储 MySQL GUID/UUID

Storing MySQL GUID/UUIDs(存储 MySQL GUID/UUID)
本文介绍了存储 MySQL GUID/UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我能想到的将 UUID() 生成的 MySQL GUID/UUID 转换为二进制 (16) 的最佳方法:

This is the best way I could come up with to convert a MySQL GUID/UUID generated by UUID() to a binary(16):

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

然后将其存储在 BINARY(16) 中

And then storing it in a BINARY(16)

这样做有什么我应该知道的含义吗?

Are there any implications of doing it this way that I should know of?

推荐答案

影响不大.它会稍微减慢查询速度,但您几乎不会注意到它.

Not many implications. It will slow down the queries a little, but you will hardly notice it.

UNIQUEIDENTIFIER 无论如何都会在内部存储为 16 字节二进制.

UNIQUEIDENTIFIER is stored as 16-byte binary internally anyway.

如果您要将二进制文件加载到客户端并在那里解析,请注意 bit order,它可能具有不同于初始 NEWID() 的其他字符串表示.

If you are going to load the binary into a client and parse it there, note the bit order, it may have other string representation than the initial NEWID().

OracleSYS_GUID() 函数很容易出现这个问题,将其转换为字符串会在客户端和服务器上产生不同的结果.

Oracle's SYS_GUID() function is prone to this issue, converting it to a string gives different results on client and on server.

这篇关于存储 MySQL GUID/UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)