Does a utf8_unicode_cs collation exist?

后端 未结 2 1561
独厮守ぢ
独厮守ぢ 2021-01-02 03:33

Does anyone know if a utf8_unicode_cs collation for MySQL exists? So far, my searches have come up dry. If it simply doesn\'t exist yet, is it fairly straight-forward to cre

2条回答
  •  长情又很酷
    2021-01-02 04:13

    I came across the same issue and after some Googling, it seems that MySQL doesn't include it. To "simulate it", as you put it,

    1) To ensure case-sensitivity in the DB: set the table column to utf8_bin collation
    This allows:

    • strict SELECTs: SELECT "Joe" will NOT return rows with "joe" / "joE" / "jOe" / etc
    • strict UNIQUE index: a column with a UNIQUE index will treat case differences as different values. For example, if a utf8_unicode_ci collation is used, inserting "Joe" on a table that already has "joe" will trigger a "Duplicate key" error. If ut8_bin is used, inserting "Joe" will work fine.

    2) To get the proper ordering in results: add the collation to the SQL query:

    SELECT ... ORDER BY column COLLATE utf8_unicode_ci
    

提交回复
热议问题