Case Sensitivity in MySQL Collation
MySQL provides a wide range of collation types to handle data comparison and sorting. However, finding a collation that supports case sensitivity can be a bit challenging.
Is Case Sensitivity Supported?
The standard MySQL collations marked with "_ci" at the end inherently follow case-insensitive rules. However, according to the MySQL Manual, there are collations suffixed with "_cs" that offer case sensitivity.
Finding Case-Sensitive Collations
To view a list of "_cs" collations, execute the following query:
SHOW COLLATION WHERE COLLATION LIKE "%_cs"
Case Sensitivity with UTF-8
Although UTF-8 is commonly used, there are no "utf8_*_cs" collations available in MySQL. Instead, "utf8_bin" can be utilized for case-sensitive UTF-8 fields. Keep in mind that this may impact ordering (ORDER BY), which can be resolved using:
ORDER BY column COLLATE utf8_general_ci
These findings are sourced from MySQL forums and underscore the limited options for case-sensitive collations, particularly with UTF-8.
The above is the detailed content of How Can I Achieve Case Sensitivity in MySQL Collations?. For more information, please follow other related articles on the PHP Chinese website!