MySQL case sensitivity table name on MacOS with case insensitive file system

前端 未结 7 1034
梦如初夏
梦如初夏 2021-01-19 11:55

I have researched a lot and what I understand to make database tables name sensitive, you have to set the variable lower_case_table_names=0. Im on osX. I did this change in

7条回答
  •  深忆病人
    2021-01-19 12:30

    By default, table aliases are case-sensitive on Unix, but not so on Windows or macOS. And you can't force this on OSX.

    The MySql documentation gives the following recommendation:

    To avoid problems caused by such differences, it is best to adopt a consistent convention, such as always creating and referring to databases and tables using lowercase names. This convention is recommended for maximum portability and ease of use.

    In MySQL, databases correspond to directories within the data directory. Each table within a database corresponds to at least one file within the database directory (and possibly more, depending on the storage engine). Triggers also correspond to files. Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database, table, and trigger names. This means such names are not case-sensitive in Windows but are case-sensitive in most varieties of Unix. One notable exception is macOS, which is Unix-based but uses a default file system type (HFS+) that is not case-sensitive. However, macOS also supports UFS volumes, which are case-sensitive just as on any Unix. See Section 1.7.1, “MySQL Extensions to Standard SQL”. The lower_case_table_names system variable also affects how the server handles identifier case sensitivity, as described later in this section.

    The recommended is use lower_case_table_names=1 on all systems, but the disadvantage with this is that when you use SHOW TABLES or SHOW DATABASES, you don't see the names in the original case.

    the variable lower_case_table_names is 0 by default, which means table names are stored as specified and comparisons are case-sensitive.

    that is the possible values:

    • 0: table names are stored as specified and comparisons are case-sensitive.
    • 1: table names are stored in lowercase on disk and comparisons are not case-sensitive.
    • 2: table names are stored as given but compared in lowercase. This option also applies to database names and table aliases.

    On Windows the default value is 1. On macOS, the default value is 2. On Linux, a value of 2 is not supported; the server forces the value to 0 instead.

    and here are your answer

    You should not set lower_case_table_names to 0 if you are running MySQL on a system where the data directory resides on a case-insensitive file system (such as on Windows or macOS). It is an unsupported combination that could result in a hang condition when running an INSERT INTO ... SELECT ... FROM tbl_name operation with the wrong tbl_name lettercase. With MyISAM, accessing table names using different lettercases could cause index corruption.

    An error message is printed and the server exits if you attempt to start the server with --lower_case_table_names=0 on a case-insensitive file system.

    you can change this in my.cnf file, and you can find it using following command (if you are using unix-based system)

    mysql --help | grep cnf
    

    References:

    MySQL 5.7 Reference Manual Identifier Case Sensitivity

    MySQL 5.7 Reference Manual 5.1.7 Server System Variables

提交回复
热议问题