在linux的環境下,在mysql的配置裡會對大小寫有一定的要求的。尤其是一些雲平台提供的固定環境是配置好這些要求,所以需要對這些有一定的了解。(比如阿裡雲就會設定lower_case_table_names=1,具體分析在後面)
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)
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)
+--------------------------------+ | Tables_in_testdb | +--------------------------------+ | TABLE1| | TABLE2|
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> create table t (name varchar(10)) default charset=utf8 default collate=utf8_general_ci; Query OK, 0 rows affected (0.09 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)
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)