mysql預設是不區分大小寫的,但是在很多情況下需要大小敏感,以下總結了多種設定mysql大小寫敏感的方法。
方法一:
修改mysql server安裝目錄下的 my.ini 檔案,在mysqld節下加入下面一行 set-variable=lower_case_table_names=0 (0:大小寫敏感;1:大小寫不敏感)最後重啟一下mysql服務即可。
方法二:
一種方法是可以設定表或行的collation,使其為binary或case sensitive。在mysql中,對於column collate其約定的命名方法如下:
*_bin: 表示的是binary case sensitive collation,也就是說是區分大小寫的
*_cs: case sensitive collation,區分大小寫
*_ci: case insensitive collation,不區分大小寫
###########
# start binary collation example
###########
mysql> create table case_bin_test (word varchar(10)) character set latin1 collate latin1_bin;
query ok, 0 rows affected (0.02 sec)
mysql> insert into case_bin_test values ('frank'),('google'),('froogle'),('flickr'),('flickr');
query ok, 5 rows affected (0.00 sec)
records: 5 duplicates: 0 warnings: 0
mysql> select * from case_bin_test where word like 'f%';
+---------+
| word |
+---------+
| froogle |
| flickr |
+---------+
2 rows in set (0.00 sec)
mysql> select * from case_bin_test where word like 'f%';
+---------+
| word |
+---------+
| frank |
| flickr |
+---------+
4 rows in set (0.00 sec)
###########
# end
###########
方法三:
###########
# start case sensitive collation example
###########
mysql> create table case_cs_test (word varchar(10)) character set latin1 collate latin1_general_cs;
query ok, 0 rows affected (0.08 sec)
mysql> insert into case_cs_test values ('frank'),('google'),('froogle'),('flickr'),('flickr');
query ok, 5 rows affected (0.00 sec)
records: 5 duplicates: 0 warnings: 0
mysql> select * from case_cs_test where word like 'f%';
+---------+
| word |
+---------+
| frank |
| flickr |
+---------+
4 rows in set (0.00 sec)
mysql> select * from case_cs_test where word like 'f%';
+---------+
| word |
+---------+
| froogle |
| flickr |
+---------+
2 rows in set (0.00 sec)
###########
# end
###########
方法四:就是在查詢時指定collation
mysql> create table case_test (word varchar(10)) character set latin1;
query ok, 0 rows affected (0.01 sec)
mysql> insert into case_test values ('frank'),('google'),('froogle'),('flickr'),('flickr');
query ok, 7 rows affected (0.01 sec)
records: 7 duplicates: 0 warnings: 0
mysql> select * from case_test where word like 'f%';
+---------+
| word |
+---------+
| frank |
| froogle |
| flickr |
| flickr |
+---------+
6 rows in set (0.01 sec)
mysql> select * from case_test where word like 'f%';
+---------+
| word |
+---------+
| frank |
| froogle |
| flickr |
| flickr |
+---------+
6 rows in set (0.01 sec)
mysql> select * from case_test where word collate latin1_bin like 'f%';
+---------+
| word |
+---------+
| frank |
| flickr |
+---------+
4 rows in set (0.05 sec)
mysql> select * from case_test where word collate latin1_bin like 'f%';
+---------+
| word |
+---------+
| froogle |
| flickr |
+---------+
2 rows in set (0.00 sec)
mysql> select * from case_test where word like 'f%' collate latin1_bin;
+---------+
| word |
+---------+
| froogle |
| flickr |
+---------+
2 rows in set (0.00 sec)
mysql> select * from case_test where word like 'f%' collate latin1_bin;
+---------+
| word |
+---------+
| frank |
| flickr |
+---------+
4 rows in set (0.01 sec)
mysql> select * from case_test where word like 'f%' collate latin1_general_cs;
+---------+
| word |
+---------+
| frank |
| flickr |
+---------+
4 rows in set (0.04 sec)
方法五:
要讓mysql查詢區分大小寫,可以:
select * from table_name where
binary a like
'a%'
select * from table_name where
binary a like
'a%'
也可以在建表時,加以標識
create
table table_name(
a varchar (20) binary)
mysql 區分大小寫 大小寫敏感 配置
linux下mysql預設區分大小寫 windows下mysql預設不區分大小寫 檢視是否區分大小寫 lower case table names引數詳解 lower case table names 0 其中 0 區分大小寫,1 不區分大小寫 mysql在linux下資料庫名 表名 列名 別名大小...
Mysql區分大小寫(對大小寫敏感)的問題解決
問題起因 系統上線時,原本在windows下開發的時候除錯完一切正常。轉到linux後就報錯查不到表 如下圖1 納悶了,查了一下資料庫表 如圖2 明明就在那兒啊。圖1 圖2 然後把sql語句複製出來單獨查詢發現這個大寫的表名找不到了,改成小寫的就找到了。問題定位到了,解決也就是一層窗戶紙了。問題解決...
MySQL大小寫敏感
mysql大小寫敏感的解決方案 注 關於lower case table names引數對錶名稱或資料庫名稱大小寫敏感的控制。unix下預設為0,也就是大小寫敏感的 windows下預設為1,不敏感 macos預設為2,儲存區分大小寫,但是在查詢時會轉換為小寫。對於在大小寫不敏感的系統 window...