mysql uuid多少位,MySQL UUID()何时不唯一?

What happens when a UUID() generated by MySQL is not unique? If this is for a column that is a primary key, does MySQL error out, or does it try generating another UUID until a truly unique one is found?

解决方案

Well, if you call UUID() twice and get the same results, the most problematic thing would be that "stuff is broken" (tm). It's supposed to be unique and it should be always, as far as I know.

There would be no "regenerate" code available: the function is designed to create unique keys even across computers, so how could it even know its result was not unique?

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.

Maybe you mean something else? For instance, if you use UUID() to generate somethingthat should be unique (like a primary key, or a Unique field etc), and you've previously added the same number (like for instance you called UUID() once, but inserted something twice), then you'll just get the default error you get when adding non-unique content to a place that should be unique. You will not get a new one.

some reading material about the uniqueness:

Check the link on that manual for the actual definition (but that's quite a read, so you might skip this one): https://www2.opengroup.org/ogsys/jsp/publications/PublicationDetails.jsp?catalogno=c706

Some easier to understand metrics on probability of dubplicates here: http://en.wikipedia.org/wiki/Universally_unique_identifier

there is some talk on the mysql site (forums etc) too, about using it as primary key, but as i'm at work and short on time, you need to search for that yourself :)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值