当前位置:网站首页>mysql 数据库字段查询区分大小写设置
mysql 数据库字段查询区分大小写设置
2022-06-26 09:32:00 【川流不息的车呀】
使用navicat 创建数据库,字符集选择utf8,排序规则不选择的话,创建成功话,查看数据库属性发现给默认设置了排序规则如下图:

创建成功后,创建表testcase,通过 show CREATE TABLE testcase查看建表语句,如下是不进行大小写区分的[排序规则:utf8_genera_ci不区分大小写]
CREATE TABLE `testcase` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
INSERT INTO `testcase` ( `name`, `time`) VALUES ('WX0001', '2022-06-22');
INSERT INTO `testcase` ( `name`, `time`) VALUES ('wx0001', '2022-06-22');
通过上述插入语句,因为不区分大小写,带有唯一索引字段的name的第二条记录插入失败

修改表字符集
ALTER TABLE testcase CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
utf8_bin将字符串中的每一个字符用二进制数据存储,区分大小写
目前数据库有多少行,就会影响多少行
CREATE TABLE `testcase` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
修改成功后,再次插入刚刚失败的小写字段值
INSERT INTO `testcase` ( `name`, `time`) VALUES ('wx0001', '2022-06-22');
可以看到插入成功,此时大小写区分设置成功

边栏推荐
- 【Open5GS】Open5GS安装配置
- 首期Techo Day腾讯技术开放日,628等你
- 0 basic how to make a cool leadership cockpit?
- Thinkphp5 using the composer installation plug-in prompts that the PHP version is too high
- Self taught neural network series - 1 Basic programming knowledge
- 《一周搞定模电》—基本放大电路
- Curriculum learning (CL)
- pcl install
- Pycharm occasionally encounters low disk space
- Jz2440 - - - utiliser le programme de gravure uboot
猜你喜欢

Yolov5 results Txt visualization

The first techo day Tencent technology open day, 628

Detectron2 save (according to maxap50) model during training_ best. PTH weight

《一周搞定模电》-光耦等元器件

Pycharm occasionally encounters low disk space

Edge computing is the sinking and extension of cloud computing capabilities to the edge and user sides

Classified catalogue of high quality sci-tech periodicals in the field of computing
![Li Kou 399 [division evaluation] [joint query]](/img/25/ea7d526c0628f11277141f51d4ccae.png)
Li Kou 399 [division evaluation] [joint query]

Comprehensive interpretation! Use of generics in golang

Badge collection 6:api\_ Use of level
随机推荐
《一周搞定模电》—集成运算放大器
Course paper: Copula modeling code of portfolio risk VaR
Self taught programming series - 2 file path and text reading and writing
【AAAI 2021】Few-Shot One-Class Classification via Meta-Learning 【FSOCC via Meta-learning】
板端电源硬件调试BUG
"One week's work on Analog Electronics" - diodes
MySQL单表500万条数据增、删、改、查速度测试
"One week's work on Analog Electronics" - integrated operational amplifier
QPM suspended window setting information
《一周搞定模电》—功率放大器
[open5gs] open5gs installation configuration
Jetson TX2 installing the SciPy Library
xsync同步脚本的创建及使用(以Debian10集群为例)
Self taught neural network series - 3. First knowledge of neural network
Origin of QPM
【C】 Frog jumping steps and Hanoi Tower problem (recursion)
Merrill Lynch data technology expert team | application of recommendation of relevant contents in group system data retrieval
There is a strong demand for enterprise level data integration services. How to find a breakthrough for optimization?
【CVPR 2021】DatasetGAN: Efficient Labeled Data Factory with Minimal Human Effort
Solutions for safety management and control at the operation site