Solve the problem that MySQL queries are case insensitive bitsCN.com
Today, the same data can be found in case-insensitive input conditions when querying data. For example, if you enter aaa, aaA, or AAA to query the same results, the query conditions are case-insensitive. Because the program uses the hibernate framework to access the mysql database. At first, I thought it was a problem with hibernate. After tracing the hibernate code, we did not see the case-insensitive conversion step. Finally, we confirmed that hibernate only converts hql to SQL. The case sensitivity is irrelevant to hibernate. Therefore, I suspect Mysql problems. Make an experiment: directly use the client to query the database using SQL. It is found that the size is not sensitive. You need to set collate by querying the data ). Collate rule: * _ bin: indicates binary case sensitive collation, that is, case sensitive * _ cs: case sensitive collation, case sensitive * _ ci: case insensitive collation, case-insensitive solution. 1. query conditions can be included in binary. For example: select * from TableA where columnA like binary ('aaa'); 2. you can MODIFY the collation of this field to binary, for example, alter table tablename modify column columnname varchar (50) binary character set utf8 COLLATE utf8_bin default null. The problem is solved.
The author sends
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.