MySQL fuzzy query (like) case-sensitive

Source: Internet
Author: User

Problem Description: Through the above statement, you will find that the MySQL like query is not case-sensitive, because my mistake, Joe was written to find this stuff. But, sometimes, we need to be case-sensitive, what should we do? Here's how to fix it:

Method One (Specify case-sensitive when querying)

Quite simply, add a binary to the back of like and apply to the case where the table structure is not easy to change. Most people find this problem, often the structure of the table can not be changed, so this method is very good.

Then there are other ways to set the size of the table.

can also be identified when the table is built

CREATE TABLE table_name (

A varchar (a) binary

)

In-depth understanding:

The first thing you need to know is that in MySQL, the naming method for column collate's conventions is as follows:

*_bin: Indicates a binary case sensitive collation, which means

*_cs:case sensitive collation, case-sensitive

*_ci:case insensitive collation, case insensitive

Set the character to be case-sensitive during the construction of the table, and then insert the 3 record test.

Most of the time, our first build table is not comprehensive, I think, can be added later, modify the characteristics of the table, this is possible.

Just the Student_web watch.

But, it failed. I don't know why, I hope you can give me help.

The above is case-sensitive using _bin, and you can also use the

CREATE TABLE table_name (Word VARCHAR) CHARACTER SET latin1 COLLATE latin1_general_cs;

Optionally, specify collation at query time

When the table is built:mysql> CREATE TABLE table_name (Word VARCHAR) CHARACTER SET latin1;

Query:mysql> SELECT * FROM table_name WHERE word COLLATE latin1_bin like ' f% '; Put it in front of like

or:mysql> SELECT * FROM table_name WHERE word like ' f% ' COLLATE latin1_bin; Put it in the last

or:mysql> SELECT * from case_test WHERE word like ' f% ' COLLATE latin1_general_cs;

Reference: http://www.cnblogs.com/pinnasky/archive/2012/09/11/2680264.html

MySQL fuzzy query (like) case-sensitive

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.