色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

MySQL 字符類型大小寫敏感

瀏覽:30日期:2023-10-08 11:25:32

mysql字符類型默認(rèn)是不區(qū)分大小寫的,即select * from t where name=’AAA’與=’aaa’沒區(qū)別,以下是測試的例子

(root@localhost)[hello]> create table test1(id int, name varchar(10));(root@localhost)[hello]> insert into test1 values(1,’aaa’),(2,’AAA’),(3,’bbb’),(4,’BbB’);(root@localhost)[hello]> select * from test1;+------+------+| id | name |+------+------+| 1 | aaa || 2 | AAA || 3 | bbb || 4 | BbB |+------+------+(root@localhost)[hello]> select * from test1 where name = ’AAA’;+------+------+| id | name |+------+------+| 1 | aaa || 2 | AAA |+------+------+(root@localhost)[hello]> select * from test1 where name = ’aaa’;+------+------+| id | name |+------+------+| 1 | aaa || 2 | AAA |+------+------+

可以看到此時(shí)where條件后面的’AAA’與’aaa’,查出來的結(jié)果沒啥區(qū)別。

如果只想找出’AAA’的可以有以下幾種辦法1.在sql中加入binary關(guān)鍵字

(root@localhost)[hello]> select * from test1 where binary name = ’AAA’;+------+------+| id | name |+------+------+| 2 | AAA |+------+------+

2.修改列的定義

先查看原始表的定義

(root@localhost)[hello]> show create table test1G*************************** 1. row *************************** Table: test1Create Table: CREATE TABLE `test1` ( `id` int(11) DEFAULT NULL, `name` varchar(10) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

修改表test1的name列

alter table test1 modify column name varchar(10) character set utf8mb4 collate utf8mb4_bin default null;

collate utf8mb4_bin表示where過濾或者order by排序區(qū)分大小寫

此時(shí)查看test1的定義

(root@localhost)[hello]> show create table test1G*************************** 1. row *************************** Table: test1Create Table: CREATE TABLE `test1` ( `id` int(11) DEFAULT NULL, `name` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

接著再執(zhí)行查詢語句

(root@localhost)[hello]> select * from test1 where name=’AAA’;+------+------+| id | name |+------+------+| 2 | AAA |+------+------+

下面再創(chuàng)建一張test2表,就會發(fā)現(xiàn)上面修改列的語句其實(shí)相當(dāng)于在創(chuàng)建表時(shí)varchar后面跟binary

(root@localhost)[hello]> create table test2(id int, name varchar(10) binary);(root@localhost)[hello]> show create table test2G*************************** 1. row *************************** Table: test2Create Table: CREATE TABLE `test2` ( `id` int(11) DEFAULT NULL, `name` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

下面介紹如何設(shè)置字符大小寫敏感

數(shù)據(jù)庫級別設(shè)置字符大小寫敏感

創(chuàng)建

create database <db_name> default character set utf8mb4 collate utf8mb4_bin;

修改

alter database <db_name> default character set utf8mb4 collate utf8mb4_bin; 表級別設(shè)置字符大小寫敏感

創(chuàng)建

create table <tb_name> (......) engine=innodb default charset=utf8mb4 collate=utf8mb4_bin;

修改

alter table <tb_name> engine=innodb default charset=utf8mb4 collate=utf8mb4_bin; 列級別設(shè)置字符大小寫敏感

創(chuàng)建

create table <tb_name> (`field1` varchar(10) character set utf8mb4 collate utf8mb4_bin,......)

修改

alter table <tb_name> modify column `field1` varchar(10) character set utf8mb4 collate utf8mb4_bin default null;

繼承關(guān)系是列-->表-->庫,優(yōu)先級是列>表>庫

以上就是MySQL 字符類型大小寫敏感的詳細(xì)內(nèi)容,更多關(guān)于MySQL 字符類型大小寫的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: MySQL 數(shù)據(jù)庫
相關(guān)文章:
主站蜘蛛池模板: 久草免费在线播放 | 波多野结衣3女同在线观看 波多野结衣aⅴ在线 | 国产欧美一区二区 | 韩国good三级在线观看久 | 日韩欧美国产视频 | 日本亚欧乱色视频在线网站 | 香港激情三级做爰小说 | 国产三级一区二区 | 国产无套视频在线观看香蕉 | 欧美日本在线三级视频 | 午夜一区二区福利视频在线 | 亚洲一区中文 | 伊人365影院 | 朝鲜美女免费一级毛片 | 男人的天堂免费网站 | 亚洲乱码国产一区网址 | 日本 片 成人 在线 日本68xxxxxxxxx老师 | 中国一级毛片在线观看 | 日韩视频在线观看一区 | 欧美成人伊人十综合色 | 国产99视频精品免费观看9e | 久久免费手机视频 | 日韩激情中文字幕一区二区 | 亚洲国产精品久久久久秋霞不卡 | 国产激情一级毛片久久久 | a欧美在线 | 一级毛片视频免费观看 | 免费人成观看在线网 | 午夜精品成人毛片 | 黄色片日本人 | 欧美在线一二三区 | 午夜在线视频一区二区三区 | 成人国产免费 | 一级女性全黄久久生活片 | 欧美日韩高清观看一区二区 | 亚洲国产欧美视频 | 特级毛片免费观看视频 | 欧美二区在线观看 | 免费视频 久久久 | 欧美另类69xxxxx 视频 | 九草在线免费观看 |