lower_case_table_names:表名大小写敏感度
0表示使用Create语句指定的大小写保存文件
1表示大小写敏感,文件系统以小写保存
2表示使用Create语句指定的大小写保存文件,但MySQL会将之转化为小写
(当Linux设置为2时,错误日志显示[Warning]
lower_case_table_names was set to 2, even though your the file system ‘/home/mysql/master_a/data/‘ is case sensitive.
Now setting lower_case_table_names to 0 to avoid future problems.)
(2)变量更新
mysql> show variables like ‘lower%‘;
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| lower_case_file_system | OFF |
| lower_case_table_names | 0 |
+------------------------+-------+
2 rows in set (0.01 sec)
--修改发现变量为只读变量
mysql> set global lower_case_table_names=1;
ERROR 1238 (HY000): Variable ‘lower_case_table_names‘ is a read only variable
修改my.cnf后重启数据库
lower_case_table_names=1
mysql> show variables like ‘lower%‘;
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| lower_case_file_system | OFF |
| lower_case_table_names | 1 |
+------------------------+-------+
2 rows in set (0.01 sec)
指定校对为区分大小写
mysql> create table b(id varchar(10)) default charset=utf8 default collate=utf8_bin;
Query OK, 0 rows affected (0.03 sec)sec)
mysql> insert into b values (‘A‘),(‘a‘),(‘B‘);
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from b where id like ‘a‘;
+------+
| id |
+------+
| a |
+------+
1 row in set (0.00 sec)
mysql> select id,count(*) from b group by id;
+------+----------+
| id | count(*) |
+------+----------+
| A | 1 |
| B | 1 |
| a | 1 |
+------+----------+
3 rows in set (0.03 sec)
mysql> insert into t values(‘a‘),(‘A‘),(‘B‘),(‘b‘),(‘c‘);
Query OK, 5 rows affected (0.02 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from t where name like ‘a‘;
+------+
| name |
+------+
| a |
| A |
+------+
2 rows in set (0.01 sec)
mysql> select name,count(*) from t group by name;
+------+----------+
| name | count(*) |
+------+----------+
| a | 2 |
| B | 2 |
| c | 1 |
+------+----------+
3 rows in set (0.04 sec)
不过如果字段类型是binary则肯定会区分大小写
mysql> alter table t change name name varchar(10) binary;
Query OK, 5 rows affected (0.08 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from t where name like ‘A‘;
+------+
| name |
+------+
| A |
+------+
1 row in set (0.00 sec)
mysql> select name,count(*) from t group by name;
+------+----------+
| name | count(*) |
+------+----------+
| A | 1 |
| B | 1 |
| a | 1 |
| b | 1 |
| c | 1 |
+------+----------+
5 rows in set (0.01 sec)