Case sensitivity in MySQL database search

Source: Internet
Author: User
Tags character set mysql mysql database

By default, MySQL searches are case-insensitive (but some character sets are always case-sensitive, such as Czech). This means that if you use col_name like ' a% ' to search, you will get all the columns starting with a or a. If you intend to make the search case-sensitive, make sure that one of the operands has case-sensitive or binary proofing. For example, if you are comparing columns and strings that all apply to the latin1 character set, you can use the COLLATE operator to make the 1 operands have Latin1_general_cs or latin1_bin proofing properties. For example:

col_name COLLATE latin1_general_cs LIKE 'a%'
col_name LIKE 'a%' COLLATE latin1_general_cs
col_name COLLATE latin1_bin LIKE 'a%'
col_name LIKE 'a%' COLLATE latin1_bin

If you want to always handle a column in a case-sensitive manner, you can declare it by using case-sensitive or binary proofing.

Simple comparison operations (>=,, =,,, <=, sorting, and grouping) are based on the "sorted value" of each character. Characters with the same sort value (such as ' e ', ' e ', and ' é ') will be treated as the same character.

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.