MySQL is case sensitive.

Source: Internet
Author: User
MySQL is case sensitive based on the user's operating system. You can force mysqld to be started with the-Olower_case_table_names1 parameter (if -- defaults-file... \ my. if the cnf parameter is used to read the specified configuration file and start mysqld, you need to add a line lower_case_tabl under the [mysqld] section of the configuration file.

MySQL is case sensitive based on the user's operating system. You can force the-O lower_case_table_names = 1 parameter to start mysqld (if -- defaults-file =... \ my. if the cnf parameter is used to read the specified configuration file and start mysqld, you need to add a line lower_case_tabl under the [mysqld] section of the configuration file.

In this way, MySQL automatically converts all table names to lowercase characters when creating and searching (this option is 1 by default in Windows and 0 in Unix. From MySQL 4.0.2, this option also applies to the database name ).

When you change this option, you must first convert the old table name to lowercase letters before starting mysqld.

In other words, if you want to retain the case-sensitive characters when creating a table in the database, set this parameter to 0: lower_case_table_names = 1.

Otherwise, you will find that the same sqldump script imports different results in different operating systems (all uppercase characters in Windows are changed to lowercase letters ).

Note:

On Win32, although the database and table names are case-insensitive, you should not reference a given database and table in the same query using different cases. The following query will not work because it references a table as my_table and MY_TABLE:

The Code is as follows:

1. Mysql> SELECT * FROM my_table WHERE MY_TABLE.col = 1;

2. Column name

The column names are case-insensitive in all cases.

3. Table alias

Table aliases are case sensitive. The following query will not work because it uses a and A to reference aliases:

The Code is as follows:

1. Mysql> SELECT col_name FROM tbl_name AS

2. WHERE a. col_name = 1 or a. col_name = 2;

4. Column alias

The column alias is case-insensitive.

5. String comparison and pattern matching

By default, Mysql search is case insensitive (although some character sets never ignore Mysql Case sensitivity, such as Czech ). This means that if you search by col_name LIKE 'a % ', you will get all column values starting with a or. If you want to make this search case sensitive, use INDEX (col_name, "A") = 0 to check A prefix. Or if the column value must be "A", use STRCMP (col_name, "A") = 0.

Simple comparison operations (> =,>, =, <, <=, sort, and aggregation) are based on the "Sort value" of each character ". Characters with the same sorting value (such as E and e) are considered to be the same character!

LIKE is compared to the upper-case values of each character ("E" = "e ").

If you want a column to always be considered Mysql case-sensitive, declare it as BINARY.

For example:

The Code is as follows:


1. Mysql> SELECT "E" = "e", "E" = BINARY "e ";
2. + --------- + -------------- + | "E" = "e" | "E" = BINARY "e"
| + --------- + ---------------- + | 1 | 0 | + --------- + ---------------- +

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.