Home >Database >Mysql Tutorial >How Can I Achieve Case-Sensitive Comparisons in MySQL Collations?

How Can I Achieve Case-Sensitive Comparisons in MySQL Collations?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-21 07:08:10236browse

How Can I Achieve Case-Sensitive Comparisons in MySQL Collations?

Case Sensitivity in MySQL Collation

It is common knowledge that MySQL collations end with "_ci," indicating case-insensitive comparisons. However, there may be scenarios where users require case-sensitive collation.

Solution:

According to the MySQL Manual: http://dev.mysql.com/doc/refman/5.0/en/charset-mysql.html

  1. Utilize the "_cs" suffix to set case sensitivity in collation.
  2. Obtain a list of "_cs" collations using the query:
SHOW COLLATION WHERE COLLATION LIKE "%_cs"

Additional Considerations for UTF-8:

Research indicates that there are no UTF-8 collations using "_cs" in MySQL. For UTF-8 fields with case sensitivity, it is recommended to use "utf8_bin."

Note:

"utf8_bin" can affect ORDER BY functionality. To mitigate this, use the following syntax:

ORDER BY column COLLATE utf8_general_ci

References:

  • http://forums.mysql.com/read.php?103,19380,200971#msg-200971
  • http://forums.mysql.com/read.php?103,156527,198794#msg-198794

The above is the detailed content of How Can I Achieve Case-Sensitive Comparisons in MySQL Collations?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn