三种方法设置mysql/ target=_blank class=infotextkey>mysql数据库select查询区分大小写
1、方法二,可以设置表或行的collation,使其为binary或case sensitive。
在mysql教程中,对于column collate,其约定的命名方法如下:
2、方法二
3、方法三,在查询时指定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)