I have a table, students
, with 3 columns: id
, name
, and age
.
I have a UNIQUE
index Index_2
on
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.
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")