加入收藏 | 设为首页 | 会员中心 | 我要投稿 大连站长网 (https://www.0411zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

mysql uuid是不是有序增加的

发布时间:2022-01-13 11:57:26 所属栏目:MySql教程 来源:互联网
导读:今天就跟大家聊聊有关mysql uuid是不是有序增加的,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。 A UUID is designed as a number that is globally unique in space and time. Two calls to
        今天就跟大家聊聊有关mysql uuid是不是有序增加的,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
 
 
     A UUID is designed as a number that is globally unique in space and time. Two calls to UUID() are
     expected to generate two different values, even if these calls are performed on two separate computers
     that are not connected to each other.
      uuid是世界上唯一的,就算两个没有任何关系的计算机uuid也是不同的
 
但是文档上却没有说到他是不是有序的,网上都说uuid是无序,我想一个场景试一下:
 
场景解释:
建一个表,里面有两个字段 uuid和时间。
每一秒向这个表里插入一条数据,分别是 uuid()和now()
 
插入一段时间之后,如果按id排序和按t_date排序得到的结果是一样的,那么应该可以证明uuid是有序的,如果排序结果不一样,那么是无序的。
 
我这里两个进程同时插入,并且跑了两个小时
 
模拟过程:
在mysql 5.6上测试
mysql> create table song( id char(36), t_date datetime);
Query OK, 0 rows affected (0.00 sec)
 
 
cat insert.sh
#!/bin/bash
while true; do
mysql -h20.13.52.100 -P3306 -uroot -ptest  -e "insert into test.song select uuid(),now();"
sleep 1
done
 
 
nohup sh insert.sh &
nohup sh insert.sh &
 
两个一起插入
 
运行大概两个小时,停掉insert.sh后:
 
mysql -h20.13.52.100 -P3306 -uroot -ptest  -e "select * from test.song order by t_date;" > a.log
mysql -h20.13.52.100 -P3306 -uroot -ptest  -e "select * from test.song order by id;" > b.log
diff a.log b.log  -y > c.log
 
[root@10-13-59-213 ~]# vim c.log
id      t_date                                                  id      t_date
b6af9995-50d2-11e6-9d61-5254005ae15d    2016-07-23 20:41:01   | 0019655a-50d5-11e6-9d61-5254005ae15d    2016-07-23 20:57:24
cc161c32-50d2-11e6-9d61-5254005ae15d    2016-07-23 20:41:37   | 001968e2-50d5-11e6-9d61-5254005ae15d    2016-07-23 20:57:24
ccafd852-50d2-11e6-9d61-5254005ae15d    2016-07-23 20:41:38   <
cd495dc1-50d2-11e6-9d61-5254005ae15d    2016-07-23 20:41:39   <
 
从c.log中可以看到a.log和b.log的不同。 那么 uuid()是无序的
 
 
看完上述内容,你们对mysql uuid是不是有序增加的有进一步的了解吗?

(编辑:大连站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!