【问题标题】:How can I force the value of a MySQL query to use a particular collation?如何强制 MySQL 查询的值使用特定的排序规则?
【发布时间】:2011-10-03 21:10:52
【问题描述】:

我想用UUID()来生成主键。

经过一番调查,我认为这应该可行:

INSERT INTO aTable (`id`) VALUES (UNHEX(REPLACE(UUID(),'-','')));

其中id 的类型为BINARY(16)

不幸的是,UUID() 返回一个使用utf8_general_ci 排序规则的值。我的数据库的其余部分使用utf8_unicode_ci,这意味着我收到以下错误:

#1270 - Illegal mix of collations (utf8_general_ci,COERCIBLE), (utf8_unicode_ci,COERCIBLE), (utf8_unicode_ci,COERCIBLE) for operation 'replace'

我怎样才能说服UUID()好好演奏并使用utf8_unicode_ci

【问题讨论】:

    标签: mysql utf-8 collation uuid


    【解决方案1】:
    INSERT INTO aTable (`id`) VALUES (UNHEX(REPLACE(UUID() COLLATE utf8_unicode_ci,'-','')));
    

    【讨论】:

      猜你喜欢
      • 2020-01-22
      • 1970-01-01
      • 2012-12-16
      • 2013-05-10
      • 1970-01-01
      • 2011-07-24
      • 2011-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多