MySQL:uuid_short 是如何生成的?

标签 mysql

我有 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/

相关文章:

mysql - 设置 crontab 以停止和启动 mysql 和 httpd 的正确方法

mysql - DB2 使用日期和时间显示用户的最新行记录

mysql - SQL 查找两个计数的百分比

mysql - 在mysql中创建一个表

mysql - SQL-如何将两个表与具有不同条件的两个表计数组合起来

mysql - 执行查询以获取数据行中 user_id id 的前 3 次出现?

php - 如何连接 SQL 查询以从数据库获取变量?

c# - 在表单之间传递 MySql DB 数据

mysql - 为什么我的自定义 MySQL 函数比查询中的内联函数慢得多?

php foreach,使用codeigniter出现两次的人