SoFunction
Updated on 2025-03-09

MySQL's like problem, super powerful killing! ! !

Method 1:
The solution is to add the "binary" attribute to the fields containing Chinese to make it a binary comparison, for example, change "name char(10)" to "name char(10)binary".
Method 2:
If you use source code to compile MySQL, you can use the --with-charset=gbk parameter when compiling MySQL, so that MySQL will directly support Chinese search and sorting.
Method 3:
You can use Mysql’s locate function to judge. Taking the above problem as an example, the usage method is:
SELECT * FROM table WHERE locate(field,'Li') > 0;
Method 4:
Change your Select statement to this, SELECT * FROM TABLE WHERE FIELDS LIKE BINARY '%FIND%'

The reason for the problem is: In MySQL, when sorting and searching Chinese characters, the sorting and searching results are wrong. This situation exists in many versions of MySQL. If this problem is not solved, then MySQL will not be able to actually process Chinese.
The reason for this problem is that MySQL is case-insensitive when querying strings. When deducting MySQL, ISO-8859 character set is generally used as the default character set. Therefore, during the comparison process, Chinese encoded character case conversion causes this phenomenon.