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

断了今生、忘了曾经 提交于 2019-11-27 12:51:41

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.

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")

Change collation to latin1_german2_ci

checkout collation effects

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!