MySQL uses like to search for Chinese characters with garbled characters or with insufficient Accuracy

Source: Internet
Author: User
Select... Like %... % To find MySQLThe text field is a Chinese character, but it is found that it is messy, and many people have encountered such problems. When sorting and searching Chinese characters, the results of Chinese characters are incorrect.

The reason is that MySQL is case insensitive when looking for strings, and the character set uses ISO-8859 by default, problems may occur during conversion.

There are two solutions:

The first method is to useBinaryKeyword.

The binary operator enforces the string following it as a binary string. This can easily force the comparison of a column to be case-sensitive even if the column is not defined as binary or blob.

OriginalSQLThe statement is as follows:

Select ID, Chinese from app_name_content where Chinese like '% ze %' limit 1;

The current statement is:

Select ID, Chinese from app_name_content where Chinese like
Binary'% Ze %' limit 1;

The second method changes the field type to binary. You can also use the like statement.

In this way, you can find it accurately.


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.