我有 MySQL 5.5.24。调用 uuid_short() 几次我只得到一个递增的值:
mysql> select uuid_short();
+-------------------+
| uuid_short() |
+-------------------+
| 22851044396498953 |
+-------------------+
1 row in set (0.00 sec)
mysql> select uuid_short();
+-------------------+
| uuid_short() |
+-------------------+
| 22851044396498954 |
+-------------------+
1 row in set (0.00 sec)
但是manual说:
The UUID_SHORT() return value is constructed this way:
(server_id & 255) << 56
+ (server_startup_time_in_seconds << 24)
+ incremented_variable++;
似乎“server_startup_time_in_seconds”或“server_id”都没有变化。 (我更改了@@global.server_id
系统变量,但没有生效)。
有人知道为什么吗?
最佳答案
在我看来,该函数确实会返回指定的内容。服务器 ID 和启动时间是服务器特定的值,并且(通常)只要服务器正在运行就不会更改。短 UUID 的最低有效部分是一个增量值。 所以我假设在服务器启动后,UUID 的种子被创建,采用左移的服务器 ID 和左移的启动时间。每次创建 UUID 时都会递增并返回此值。这解释了为什么更改 @@global.server_id 变量无效。
关于MySQL:uuid_short 是如何生成的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15134326/