MySQL distinction between e and é (e acute) - UNIQUE index

前端 未结 4 489
挽巷
挽巷 2020-12-01 09:32

I have a table, students, with 3 columns: id, name, and age. I have a UNIQUE index Index_2 on

相关标签:
4条回答
  • 2020-12-01 10:03

    Change collation to latin1_german2_ci

    checkout collation effects

    0 讨论(0)
  • 2020-12-01 10:17

    I know this question is somewhat old now, but what I had to do was remove the primary key on my table and use a regular index, instead. It seems that MySQL doesn't honor utf8_bin's collation in primary keys. I'm using MySQL 5.5.

    0 讨论(0)
  • 2020-12-01 10:21

    and collation is "utf8_general_ci".

    And that's the answer. If you're using utf8_general_ci (actually it applies to all utf_..._[ci|cs]) collation then diacritics are bypassed in comarison, thus:

    SELECT "e" = "é" AND "O" = "Ó" AND "ä" = "a"
    

    Results in 1. Indexes also use collation.

    If you want to distinguish between ą and a then use utf8_bin collation (keep in mind that it also distinguish between uppercase and lowercase characters).


    By the way name and age don't guarantee any uniqueness.

    0 讨论(0)
  • 2020-12-01 10:29

    I found that

    ALTER TABLE students CHARACTER SET utf8 COLLATE utf8_bin;
    

    did not work for me, as it didn't change the collation of existing columns, as can be seen in the results of this query:

    SHOW FULL COLUMNS from students;
    

    However, the following query did the job and converted existing columns to utf8_bin collation:

    ALTER TABLE students CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
    

    (notice the "CONVERT TO")

    0 讨论(0)
提交回复
热议问题