MySQL數據表中內容大小寫區分的設置
今日hadoop部門,有新的需要根據內容大小寫過濾數據。
需求如下:
select * from mnb;
+----+------+
| id | name |
+----+------+
| 1 | mnb |
| 2 | MNB |
+----+------+
2 rows in set (0.00 sec)
select * from mnb where name='MNB';
+----+------+
| id | name |
+----+------+
| 2 | MNB |
+----+------+
1 row in set (0.00 sec)
解決方案:
1、修改sql語句
select * from mnb where name= binary 'MNB';
+----+------+
| id | name |
+----+------+
| 2 | MNB |
+----+------+
1 row in set (0.00 sec)
2、修改表字符集校驗
CREATE TABLE `mnb` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) COLLATE latin1_bin DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
3、修改my.cnf
collation_server = utf8_bin
注意:只對修改參數並重啓實例後新建的表有效果,老表還需修改表的字符集校驗