Temporary solutions for inaccurate like fuzzy query of Chinese fields in Mysql database

Source: Internet
Author: User

In mysql, some records irrelevant to query words are sometimes returned during like search. For example, when "% s %" is searched, the returned results may contain Chinese characters, but there is no s character, which is related to the Chinese encoding rules of the database.

If you want to search for all news with the title containing the letter s:

Select * from test. news where title like '% s %'

Some of the returned results contain s, while others only have Chinese characters, which is depressing (and evil, hey ).

After testing, we found that one solution is to use BINARY (YesCAST (StrAs binary)(Short) Mandatory conversion for retrieval

Select * from test. news where binary title like '% s %'

In this way, the results are relatively accurate, but there is another problem: the letters are case-sensitive and the retrieval is still incorrect, so we have to convert them again:

Select * from test. news where binary ucase (title) like '% s %'

In this case, the temporary solution will solve the problem, but the speed will slow down. We hope that the problem can be solved in the future mysql version.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.