MySQL query size-sensitive SQL statement Summary

Source: Internet
Author: User
Tags character set mysql in mysql query


The company website has the need for User name verification to verify the case. In fact, at the beginning of his registration is all the case, so there is no need to do the case verification. But now to log in the case of the verification, it is registered in the time to verify this.

But MySQL in the query string is not sensitive to case, when compiling the MySQL in general with the ISO-8859 character set as the default character set, this character set is not sensitive to case, so in the comparison process of Chinese encoded character case conversion caused this phenomenon

Later, a temporary solution using binary was found

The code is as follows Copy Code

SELECT * from table name · WHERE binary ' user ' = ' www.111cn.net '

The main keyword binary has it you can distinguish the case.

The code is as follows Copy Code

CREATE table table name (name varchar () binary);

If any of the fields need to be case-sensitive in the design table, you can write this.

workaround Two If you can modify the My.ini configuration to solve the case problem as follows

A. Table names are case-sensitive

Join in my.conf:

Ower_case_table_names = 0

0: Case-sensitive, 1: case-insensitive

B. Case sensitivity when inserting a query


field values need to set the binary property to be case-sensitive.

There are several ways to set up:

Set when created:

The code is as follows Copy Code

CREATE TABLE T (
A VARCHAR (A) BINARY
);

Modify using Alter:

The code is as follows Copy Code
ALTER TABLE ' tablename ' MODIFY COLUMN ' cloname ' VARCHAR (BINARY);

Directly tick binary in MySQL table editor

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.