MySQL database name, table name capitalization problem

Source: Internet
Author: User
Tags aliases naming convention

In MySQL, the database corresponds to the directory in the operating system data directory, and each table in the database corresponds to at least one file in the database directory (or possibly multiple, depending on the storage engine). Therefore, the case sensitivity of the operating system used determines the database name and the case sensitivity of the table name. This means that in most Unix, database names and table names are case-sensitive and case insensitive in Windows.

columns, indexes, stored subroutines, and trigger names are not case sensitive on any platform, and the alias of the column is not sensitive.

For Unix-like systems:

    • Database name and table name are strictly case-sensitive

    • Table aliases are strictly case-sensitive

    • Column names and column aliases are case-insensitive in all cases

    • Variable names are also strictly case-sensitive


For win systems:

    • All are case insensitive


How MySQL saves and uses the table name and database name on the hard disk is determined by the LOWER_CASE_TABLES_NAME system variable and can be set when the mysqld is started.

    • If set to 0, table names is stored as specified and comparisons is case sensitive.

    • If set to 1, table names is stored in lowercase on disk and comparisons is not case sensitive.

    • If set to 2, table names is stored as given but compared in lowercase. This option also applies to database names and table aliases.

Default lower_case_tables_name=0 on UNIX platforms


MySQL is also case insensitive when querying or string comparisons. You can specify the binary keyword to match the case.


If you use MySQL on only one platform, you typically do not need to change the lower_case_tables_name variable. However, if you want to transfer tables between platforms that are sensitive to the size of different file systems, you will encounter problems.


Naming conventions

In order to avoid case-based problems, a recommended naming convention is to define the database/table/column with all lowercase letters + underscores, without using any uppercase letters.

If you use the InnoDB engine, apply lower_case_tables_name=1 on any platform to force the name to lowercase. Please note that before restarting Mysqld, the original database name and the table name must all be converted to lowercase before lower_case_tables_name is set to 1 in the UNIX system.

This article is from the "Share Your Knowledge" blog, so be sure to keep this source http://skypegnu1.blog.51cto.com/8991766/1591571

MySQL database name, table name capitalization problem

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.