CREATE TABLE `test_save` (
`id` binary(16) NOT NULL COMMENT '主键uuid',
`created_at` timestamp NOT NULL,
`updated_at` timestamp NOT NULL,
`deleted_at` datetime DEFAULT NULL,
`remark` varchar(256) NOT NULL DEFAULT '' COMMENT '备注',
`shop_oid` varchar(100) NOT NULL DEFAULT '' COMMENT '唯一标识',
`phones` json DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `test_save_un` (`shop_oid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
insert into test_save(id,created_at,updated_at,remark,shop_oid)
values(uuid_to_bin(uuid(),true),now(),now(),'test','22'),(uuid_to_bin(uuid(),true),now(),now(),'test2','24'),
(uuid_to_bin(uuid(),true),now(),now(),'test3','25')
-- uuid_to_bin(uuid(),true) -- 将UUID转化为有序的UUID,并将字符串用二进制类型保存,这样存储空间降低为了16字节。
select bin_to_uuid(id) from test_save -- bin_to_uuid()将二进制值反转为 UUID 字符串
mysql的有序UUID
最新推荐文章于 2025-03-18 07:00:00 发布