root:[localhost][test]> show global variables like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
root:[localhost][test]> show global variables like '%coll%';
+----------------------+----------+
| Variable_name | Value |
+----------------------+----------+
| collation_connection | utf8_bin |
| collation_database | utf8_bin |
| collation_server | utf8_bin |
+----------------------+----------+
3 rows in set (0.00 sec)
root:[localhost][test]>
root:[localhost][test]>
root:[localhost][test]>
root:[localhost][test]> show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
root:[localhost][test]> show variables like '%coll%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_bin |
+----------------------+-----------------+
3 rows in set (0.00 sec)
root:[localhost][test]> set collation_connection=utf8_bin;
Query OK, 0 rows affected (0.00 sec)
root:[localhost][test]> set collation_database=utf8_bin;
Query OK, 0 rows affected (0.00 sec)
root:[localhost][test]> show variables like '%coll%';
+----------------------+----------+
| Variable_name | Value |
+----------------------+----------+
| collation_connection | utf8_bin |
| collation_database | utf8_bin |
| collation_server | utf8_bin |
+----------------------+----------+
3 rows in set (0.00 sec)
root:[localhost][test]>
root:[localhost][test]> create table t1 (c1 int, c2 varchar(10) character set utf8 collate utf8_bin) default charset=utf8 collate=utf8_bin;
Query OK, 0 rows affected (0.10 sec)
root:[localhost][test]>
root:[localhost][test]>
root:[localhost][test]> show create table t1\G
*************************** 1. row ***************************
Table: t1
Create Table: CREATE TABLE `t1` (
`c1` int(11) DEFAULT NULL,
`c2` varchar(10) COLLATE utf8_bin DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin
1 row in set (0.00 sec)
root:[localhost][test]>
root:[localhost][test]>
root:[localhost][test]> insert into t1 values(1,'a'),(2,'A');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
root:[localhost][test]> select * from t1;
+------+------+
| c1 | c2 |
+------+------+
| 1 | a |
| 2 | A |
+------+------+
2 rows in set (0.00 sec)
root:[localhost][test]> select * from t1 where c2='a';
+------+------+
| c1 | c2 |
+------+------+
| 1 | a |
+------+------+
1 row in set (0.00 sec)
root:[localhost][test]> select * from t1 where c2='A';
+------+------+
| c1 | c2 |
+------+------+
| 2 | A |
+------+------+
1 row in set (0.00 sec)