如何强制MySQL查询的值使用特定的排序规则? [英] How can I force the value of a MySQL query to use a particular collation?
本文介绍了如何强制MySQL查询的值使用特定的排序规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用UUID()
生成主键.
经过一番调查,我认为这应该可行:
After some investigation, I thought this should work:
INSERT INTO aTable (`id`) VALUES (UNHEX(REPLACE(UUID(),'-','')));
id
的类型为BINARY(16)
.
不幸的是,UUID()
返回一个使用utf8_general_ci
归类的值.我数据库的其余部分使用utf8_unicode_ci
,这意味着出现以下错误:
Unfortunately, UUID()
returns a value which uses the utf8_general_ci
collation. The rest of my database uses utf8_unicode_ci
, which means I get the following error:
#1270 - Illegal mix of collations (utf8_general_ci,COERCIBLE), (utf8_unicode_ci,COERCIBLE), (utf8_unicode_ci,COERCIBLE) for operation 'replace'
我如何说服UUID()
玩起来不错并使用utf8_unicode_ci
?
How can I persuade UUID()
to play nicely and use utf8_unicode_ci
?
推荐答案
INSERT INTO aTable (`id`) VALUES (UNHEX(REPLACE(UUID() COLLATE utf8_unicode_ci,'-','')));
这篇关于如何强制MySQL查询的值使用特定的排序规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文