Five solutions to MySQL string case sensitivity Problems

Source: Internet
Author: User

The case sensitivity of the MySQL string often causes us to suffer from the case sensitivity of the registration name when registering a website. The cause of this problem is that MySQL is case insensitive when querying strings, when programming MySQL, The ISO-8859 character set is generally used as the default character set, this character set is not case sensitive to MySQL string, therefore, the case-sensitivity conversion of Chinese Encoded Characters During the comparison process causes the MySQL string to be case-insensitive.

Method 1:

The solution is to add the "binary" attribute to a field that contains Chinese characters for binary comparison. For example, change "name char (10)" to "name char (10) binary ".

Method 2:

If you use the source code to compile MySQL, you can use the -- with -- charset = gbk parameter when compiling MySQL, so that MySQL can directly support Chinese searching and sorting.

Method 3:

You can use the locate function of Mysql to determine. The preceding problem is used as an example:
SELECT * FROM table WHERE locate (field, 'lil')> 0;

Method 4:
Change your Select statement to this way. SELECT * from table where fields like binary '% FIND %!

Method 5:
If you use compiled MySQL in Windows, you can modify the character set options in My. ini.
Default-character-set = gb2312

If your server uses the win system, Method 5 is the best solution! For a linux system, use method 2! If it is not your own machine, you can use method 1, so that your user name is case sensitive!

MySQL string segmentation implementation

Replace string with the MySQL replace Function

Usage of MySQL string connection functions

Mysql query case

How to Implement MySQL full-text Query

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.