mysql字段值如何区分大小写
今天做sql查询,发现字段值没区分大小写
mysql> select guid,type,parent_guid from api_assets where guid='3rfI2PsSrCz91mTMDgrZjE';
+------------------------+--------+------------------------+
| guid | type | parent_guid |
+------------------------+--------+------------------------+
| 3rfI2PsSrCz91mTMDgrZjE | Window | 3rfI2PsSrCz91mTMDgry9E |
| 3rfI2PsSrCz91mTMDgrzje | Member | 3rfI2PsSrCz91mTMDgrzj1 |
| 3rfI2PsSrCz91mTMDgrzjE | Plate | 3rfI2PsSrCz91mTMDgrzjU |
+------------------------+--------+------------------------+
系统:
win7
数据库版本
mysql> select version();
+------------+
| version() |
+------------+
| 5.7.26-log |
+------------+
解决方法
1.查询时指定大小写敏感
在查询时指定大小写“敏感”,加关键字“BINARY”
mysql> select guid,type,parent_guid from api_assets where BINARY guid='3rfI2PsSrCz91mTMDgrZjE';
+------------------------+--------+------------------------+
| guid | type | parent_guid |
+------------------------+--------+------------------------+
| 3rfI2PsSrCz91mTMDgrZjE | Window | 3rfI2PsSrCz91mTMDgry9E |
+------------------------+--------+------------------------+
mysql> select guid,type,parent_guid from api_assets where guid= BINARY '3rfI2PsSrCz91mTMDgrZjE';
+------------------------+--------+------------------------+
| guid | type | parent_guid |
+------------------------+--------+------------------------+
| 3rfI2PsSrCz91mTMDgrZjE | Window | 3rfI2PsSrCz91mTMDgry9E |
+------------------------+--------+------------------------+
2.定义表结构时指定字段大小写敏感
关键字“BINARY”指定guid字段大小写敏感
CREATE TABLE `api_assets` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`guid` varchar(255) BINARY NOT NULL,
……
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
MySQL允许在大多数字符串类型上使用BINARY关键字,用于指明所有针对该字段的运算是大小写敏感的
3.修改排序规则(COLLATION)
mysql> show variables like 'collation\_database';
+--------------------+-----------------+
| Variable_name | Value |
+--------------------+-----------------+
| collation_database | utf8_general_ci |
+--------------------+-----------------+
Collation以 "_ci"结尾的不区分大小写(ci——Case Ignore),以"_bin"或者"_cs"结尾的区分大小写
将Collation改为 utf8_bin(大小写敏感的)
可以为库、表、列指定Collation。
优先级为 列>表>库
eg:
mysql> CREATE DATABASE test COLLATE utf8_bin;
Query OK, 1 row affected
mysql> use test;
Database changed
mysql> show variables like 'collation\_database';
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| collation_database | utf8_bin |
+--------------------+----------+
mysql> select guid,type,parent_guid from api_assets where
guid='3rfI2PsSrCz91mTMDgrZjE';
+------------------------+--------+------------------------+
| guid | type | parent_guid |
+------------------------+--------+------------------------+
| 3rfI2PsSrCz91mTMDgrZjE | Window | 3rfI2PsSrCz91mTMDgry9E |
| 3rfI2PsSrCz91mTMDgrzje | Member | 3rfI2PsSrCz91mTMDgrzj1 |
| 3rfI2PsSrCz91mTMDgrzjE | Plate | 3rfI2PsSrCz91mTMDgrzjU |
+------------------------+--------+------------------------+
3 rows in set
mysql> ALTER TABLE `api_assets` DEFAULT CHARACTER SET=utf8 COLLATE=utf8_bin;
Query OK, 0 rows affected
Records: 0 Duplicates: 0 Warnings: 0
mysql> select guid,type,parent_guid from api_assets where guid='3rfI2PsSrCz91mTMDgrZjE';
+------------------------+--------+------------------------+
| guid | type | parent_guid |
+------------------------+--------+------------------------+
| 3rfI2PsSrCz91mTMDgrZjE | Window | 3rfI2PsSrCz91mTMDgry9E |
| 3rfI2PsSrCz91mTMDgrzje | Member | 3rfI2PsSrCz91mTMDgrzj1 |
| 3rfI2PsSrCz91mTMDgrzjE | Plate | 3rfI2PsSrCz91mTMDgrzjU |
+------------------------+--------+------------------------+
3 rows in set
mysql> ALTER TABLE `api_assets` MODIFY COLUMN `guid` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL AFTER `id`;
Query OK, 3344 rows affected
Records: 3344 Duplicates: 0 Warnings: 0
mysql> select guid,type,parent_guid from api_assets where guid='3rfI2PsSrCz91mTMDgrZjE';
+------------------------+--------+------------------------+
| guid | type | parent_guid |
+------------------------+--------+------------------------+
| 3rfI2PsSrCz91mTMDgrZjE | Window | 3rfI2PsSrCz91mTMDgry9E |
+------------------------+--------+------------------------+
1 row in set
mysql字段值如何区分大小写的更多相关文章
- Mysql的表名/字段名/字段值是否区分大小写
1.MySQL默认情况下是否区分大小写,使用show Variables like '%table_names'查看lower_case_table_names的值,0代表区分,1代表不区分. 2.m ...
- 关于mysql的表名/字段名/字段值是否区分大小写的问题
http://www.2cto.com/database/201202/121253.html 1.mysql默认情况下是否区分大小写,使用show Variables like '%table_na ...
- MySQL 字段值为NULL,PHP用json转换,传给js,显示null
这个问题出在php的json_encode环节,这个函数返回的json数据中会把空值写作null. 想通过在js端这样把null转为空字符串是不可以的: JSON.parse(JSON.stringi ...
- MySQL字段值按照拼音首字母排序
最简单.快速的方法: 将需要进行排序的字段编码设置为GBK,然后在查询时直接使用asc/desc就可以啦
- mysql字段值为null时排序问题
-- DESC 降序时候默认null值排在后面.ASC升序时默认null值排在前面,可使用 IS NULL处理 ORDER BY score desc,gmPrice IS NULL,gmPrice, ...
- MySQL存储的字段是不区分大小写的,你知道吗?
做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! 00 简单回顾 之前写过一篇关于mysql 对表大小写敏感的问题,其实在mysql中字段存储的内容是不区分大小写的,本篇进 ...
- Mysql Sql语句令某字段值等于原值加上一个字符串
MySQL连贯字符串不能利用加号(+),而利用concat. 比方在aa表的name字段前加字符'x',利用: update aa set name=concat('x',name); 替换: UPD ...
- mysql字段varchar区分大小写utf8_bin、utf8_general_ci编码区别
mysql字段varchar区分大小写utf8_bin.utf8_general_ci编码区别 在mysql中存在着各种utf8编码格式:utf8_bin将字符串中的每一个字符用二进制数据存储,区分大 ...
- Mysql数据库插入的中文字段值显示问号的问题解决
最近我使用myeclipse连接mysql数据库查询表中的数据,表中字段值为中文的字段显示问号,查了很多资料将解决方法总结如下: 步骤一:修改mysql数据库的配置文件my.ini或者my-defau ...
随机推荐
- .prop()和.attr()的区别
具有 true 和 false 两个属性的属性,如 checked, selected 或者 disabled 使用prop(),其他的使用 attr()
- 各个系统和语言对Unicode的支持 字符集和编码——Unicode(UTF&UCS)深度历险
http://www.cnblogs.com/Johness/p/3322445.html 各个系统和语言对Unicode的支持: Windows NT从底层支持Unicode(不幸的是,Window ...
- Js 日期字符串分别截取 年 月 日 时 分 秒
function shijiantime(times){ var timearr = times.replace(" ", ":").replace(/\:/g ...
- [Algorithm] 350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...
- MongoDB 聚合查询报错
1.Distinct聚合查询报错 db.users.distinct("uname") db.runCommand({"distinct":"user ...
- 05-树8 File Transfer (25 分)
We have a network of computers and a list of bi-directional connections. Each of these connections a ...
- Sequelize 数据类型
Sequelize.STRING // VARCHAR(255)Sequelize.STRING(1234) // VARCHAR(1234)Sequelize.STRING.BINARY // VA ...
- Fluent设置充分发展湍流入口(利用profile)
计算模型: 物性参数为: 密度:100kg/m3 粘度系数:0.003333kg/(m·s) 原视频下载地址: https://pan.baidu.com/s/1W3n_K-dZCVMF7M63wV2 ...
- uniapp - 点赞动画插件
更新时间: 2019/8/31 - 点击下载demo 点赞动画插件配合animate.css更好用! 该组件参考于:https://github.com/OYsun/VueStar/tree/mast ...
- pdf 中画虚线
<?php require('fpdf.php'); class PDF_Dash extends FPDF { function SetDash($black=null, $white=nul ...