1

我有 MySQL 5.5.24。Сalling 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)

但是手册说:

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系统变量,但没有效果)。

有谁知道为什么?

4

1 回答 1

1

在我看来,该函数确实返回了指定的内容。服务器 ID 和启动时间是服务器特定的值,并且(通常)只要服务器正在运行就不会改变。短 UUID 的最不重要部分是一个递增的值。所以我假设在服务器启动后为 UUID 创建一个种子,采用左移的服务器 id 和左移的启动时间。该值在每次创建 UUID 时递增并返回。这解释了为什么更改 @@global.server_id 变量没有效果。

于 2013-02-28T12:22:55.090 回答