UUID v7 和 UUID v1 之间存在几个显著的区别,主要体现在生成方式、结构、安全性和适用场景等方面。
在 https://github.com/hcymysql/mysql-component-uuid_v7 代码库中获取到component_uuid_v7.so文件(Centos 7系统),并将其拷贝到/usr/local/mysql/lib/plugin/目录下。
mysql> install component "file://component_uuid_v7";
Query OK, 0 rows affected (0.00 sec)
mysql> select uuid_v7();
+--------------------------------------+
| uuid_v7() |
+--------------------------------------+
| 0193e1e3-a6ee-7411-9c5c-0e448fd93911 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> select uuid_v7_to_timestamp("0193e1e3-a6ee-7411-9c5c-0e448fd93911");
+--------------------------------------------------------------+
| uuid_v7_to_timestamp("0193e1e3-a6ee-7411-9c5c-0e448fd93911") |
+--------------------------------------------------------------+
| 2024-12-20 10:26:53.294 |
+--------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> create table tb1 (id varbinary(16) primary key, name varchar(20),
created timestamp default current_timestamp());
Query OK, 0 rows affected (0.01 sec)
mysql> insert into tb1 (id, name) values (UUID_TO_BIN(uuid_v7()), "张三");
Query OK, 1 row affected (0.01 sec)
mysql> select BIN_TO_UUID(id), name, created from tb1;
+--------------------------------------+--------+---------------------+
| BIN_TO_UUID(id) | name | created |
+--------------------------------------+--------+---------------------+
| 0193e1e6-fee6-79ad-860d-8616086234af | 张三 | 2024-12-20 10:30:32 |
+--------------------------------------+--------+---------------------+
1 row in set (0.00 sec)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。