Detailed explanation of mysql table name ignoring case configuration method

  • 2021-07-26 09:01:07
  • OfStack

mysql under linux is case-sensitive by default. The case-sensitive setting of mysql is determined by the parameter lower_case_table_names, where:

1) lower_case_table_names = 0

Case-sensitive (that is, case-insensitive), which is the default setting. After this setting, the table name created in mysql with or without capital letters has no effect, and can be read and referenced normally.

2) lower_case_table_names = 1

Case-insensitive (that is, case-sensitive). When this is set, table names are saved in lowercase on the hard disk, and MySQL converts all table names to lowercase for storage and lookup tables. This behavior also applies to database names and table aliases.

That is to say, when mysql is set to non-partition case, when creating a library or table, regardless of using uppercase letters when creating it, it is forced to save it in lowercase after successful creation!

MySQL Under Linux database name, table name, column name, alias case rules are as follows:

1) Database names and table names are strictly case sensitive;

2) Table aliases are strictly case sensitive;

3) Column names and column aliases are case-ignorant in all cases;

4) Variable names are also strictly case sensitive;

5) MySQL is not case sensitive under Windows, but it is case sensitive by default under Linux.

6) If you want to be case-sensitive when querying the field value, you need to set the BINARY property for the field value. There are many ways to set it:
a) Settings at creation:
CREATE TABLE T(A VARCHAR(10) BINARY);
b) Modified with alter

So in different operating systems in order to make the program and database can run normally, the best way is to design tables are turned into lowercase! !

Modify mysql to be case-insensitive:

mysqladmin-uroot-p shutdown//Shutdown database in safe mode

Modify my. cnf//Add the following 1 line setting
.....
[mysqld]
lower_case_table_names=1
.....

Start mysql


Related articles: