简体   繁体   中英

MySQL / MariaDB Case Insensitive Collation Still Case Sensitive?

Using MariaDB 10.0.36, I have a user table with the collation of utf8_turkish_ci with a user_login column that stores a user's username that is also using the collation of utf8_turkish_ci with a unique index.

My understanding is that a select statement should be case insensitive, but it doesn't appear to be that way with certain usernames.

For example, I have a user with the login of GoDoIt

This statement returns no records:

SELECT * FROM user WHERE user_login = 'godoit'

However, this works:

SELECT * FROM user WHERE user_login = 'GoDoIt'

I find this strange because the username of Eric works both ways.

SELECT * FROM user WHERE user_login = 'eric' SELECT * FROM user WHERE user_login = 'Eric'

Return the the same result. So why would capitals in the middle of the string not work? I'm lowering the input username in PHP using tolower on the string before sending it to the database, and I guess this approach won't work with certain usernames.

Turkish dotless I and dotted i are two separate characters; those are not considered equal in the utf8_turkish_ci collation.

在此处输入图片说明

See the collation chart here: http://collation-charts.org/mysql60/mysql604.utf8_turkish_ci.html

Note the separate entries for the dotless I and dotted i.

Additional background here: https://en.wikipedia.org/wiki/Dotted_and_dotless_I

(Too long for a Comment. Spencer's answer is good.)

This lists the letters and states which are equal or not, and which order they are in. Here is the excerpt show ing that the dotless I's are equal to each other but considered less than the dotted I's:

utf8_turkish_ci   I=ı  Ħ=ħ  i=Ì=Í=Î=Ï=ì=í=î=ï=Ĩ=ĩ=Ī=ī=Ĭ=ĭ=Į=į=İ  ij=IJ=ij   iz J=j=j́=Ĵ=ĵ  jz

Some other things that are unusual about utf8_turkish_ci : Ö=ö -- treated as a "letter" that comes between O and P. Similarly for Ç=ç and Ğ=ğ and Ş=ş

Note: utf8mb4 and utf8 handle Turkish identically.

MySQL 6.0 died on the vine years ago; it looks like that link for the collation is out of date with respect to Ş :

mysql> SELECT 'Ş' = 'S' COLLATE utf8_turkish_ci;
+------------------------------------+
| 'Ş' = 'S' COLLATE utf8_turkish_ci  |
+------------------------------------+
|                                  0 |
+------------------------------------+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM