MySQL using like to find Chinese characters incorrect string value solution

Source: Internet
Author: User

Use Select...like%...% to find the MySQL text Type field of a Chinese, but found out is chaotic, found a lot of people also encounter such problems. When sorting and searching in Chinese, the result of Chinese characters is wrong.

The reason is that MySQL is not sensitive when looking for strings, character sets use ISO-8859 by default, and problems occur during the conversion process.

There are two ways to solve this:

The first method is to use the binary keyword.

The binary operator enforces the string following it as a binary string. This makes it easy to force comparisons of a column to be made in a letter-case-sensitive manner, even if the column is not defined as BINARY or BLOB.

The original SQL statement is this:

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

Now the statement is:

Select Id,chinese from App_name_content where Chinese like BINARY '% ze% ' limit 1;

The second method changes the field to binary type, or it can use the like statement very well.

So you can find it exactly. MySQL, I ft!. When sorting and searching in Chinese, the result of Chinese characters is wrong.

The reason is that MySQL is not sensitive when looking for strings, character sets use ISO-8859 by default, and problems occur during the conversion process.

There are two ways to solve this:

The first method is to use the binary keyword.

The binary operator enforces the string following it as a binary string. This makes it easy to force comparisons of a column to be made in a letter-case-sensitive manner, even if the column is not defined as BINARY or BLOB.

The original SQL statement is this:

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

Now the statement is:

Select Id,chinese from App_name_content where Chinese like BINARY '% ze% ' limit 1;

The second method changes the field to binary type, or it can use the like statement very well.

So you can find it exactly.

MySQL using like to find Chinese characters incorrect string value solution

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.