MySQL的存储GUID / UUID的 [英] Storing MySQL GUID/UUIDs
问题描述
这是我能想出通过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.
如果您要二进制加载到客户端和解析它在那里,注意位顺序
,它可能有其他的字符串重新presentation比初始 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()
.
甲骨文
的 SYS_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的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!