1. One way is to set the collation of a table or row so that it is binary or case sensitive. In MySQL, the naming method for column collate's conventions is as follows:
*_bin: Indicates a binary case sensitive collation, which means
*_cs:case sensitive collation, case-sensitive
*_ci:case insensitive collation, case insensitive
2. Another method
3. Another way is to specify collation at query time
mysql> CREATE TABLE case_test (Word VARCHAR) 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 LIK E ' 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_general_cs; +---------+ | Word | +---------+ | Frank | | FlicKr | +---------+ 4 rows in Set (0.04 sec)
To make MySQL queries case-sensitive, you can:
- SELECT * FROM table_name where binary a like ' a% '
- SELECT * FROM table_name where binary a like ' A% '
Note: This query is very slow and does not recommend using
can also be identified when the table is built
Create table table_name (
A varchar (a) binary
)
MySQL queries are case-sensitive