MySQL's Treatment of Special Characters: A Paradox Explained
In MySQL, executing queries involving special characters like 'Å', 'Ä', and 'Ö' often raises questions regarding result consistency. For instance, queries with 'Harligt' and 'Härligt' yield identical results, leaving users perplexed.
This phenomenon is attributed to MySQL's default collation settings, specifically "utf8_general_ci" and "utf8_unicode_ci." These collations normalize certain unicode characters, including Scandinavian letters, by equating them to their English equivalents (e.g., "Ä = A"). This normalization simplifies comparison operations and searches but can be inconvenient in certain scenarios.
To resolve this issue, consider the following options:
select * from topics where name='Harligt' COLLATE utf8_bin;
It's worth noting that case-insensitive LIKE operations in MySQL cannot be performed without the normalization of special characters. However, related discussions can be found here:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3