utf8的大小写敏感性测试及其修改方法
utf8的大小写敏感性测试及其修改方法
# 测试utf8的大小写敏感性及其修改方法 -- 以下是utf8不区分大小写
1 # 修改数据库:
2 ALTER DATABASE database_name CHARACTER SET = utf8 COLLATE = utf8_general_ci;
3 # 修改表:
4 ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
5 # 修改表字段:
6 ALTER TABLE table_name CHANGE column_name column_name VARCHAR(191) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL; -- 以下是utf8区分大小写
1 # 修改数据库:
2 ALTER DATABASE database_name CHARACTER SET = utf8 COLLATE = utf8_bin;
3 # 修改表:
4 ALTER TABLE table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
5 # 修改表字段:
6 ALTER TABLE table_name CHANGE column_name column_name VARCHAR(191) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL; -- 1、删除库
drop database if exists db2019;
mysql> drop database if exists db2019;
Query OK, 0 rows affected, 1 warning (0.00 sec) -- 2、创建字符集为utf8的库
create database db2019 DEFAULT CHARACTER SET utf8;
mysql> create database db2019 DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec) -- 3、查看建库语句
show create database db2019;
mysql> show create database db2019;
+----------+-----------------------------------------------------------------+
| Database | Create Database |
+----------+-----------------------------------------------------------------+
| db2019 | CREATE DATABASE `db2019` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+-----------------------------------------------------------------+
1 row in set (0.00 sec) -- 4、创建测试表和数据
use db2019;
-- drop table if exists tbl_test ;
create table tbl_test (
id bigint(20) NOT NULL AUTO_INCREMENT,
name varchar(20) NOT NULL,
PRIMARY KEY (id),
KEY idx_name (name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; -- 5、查看创建表的语句
-- use db2019;
show create table tbl_test\G;
mysql> show create table tbl_test\G;
*************************** 1. row ***************************
Table: tbl_test
Create Table: CREATE TABLE `tbl_test` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
PRIMARY KEY (`id`),
KEY `idx_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec) ERROR:
No query specified -- 6、查看默认字符集
-- 方法1、show variables like '%character%';
mysql> show variables like '%character%';
+--------------------------+----------------------------+
| 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)
-- 方法2、show variables like 'collation%';
mysql> show variables like 'collation%';
+----------------------+--------------------+
| Variable_name | Value |
+----------------------+--------------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+--------------------+
3 rows in set (0.00 sec) -- 8、查看默认校对规则
show collation like 'utf8%';
mysql> show collation like 'utf8%';
+--------------------------+---------+-----+---------+----------+---------+
| Collation | Charset | Id | Default | Compiled | Sortlen |
+--------------------------+---------+-----+---------+----------+---------+
| utf8_general_ci | utf8 | 33 | Yes | Yes | 1 |
| utf8_bin | utf8 | 83 | | Yes | 1 |
| utf8_bin | utf8 | 192 | | Yes | 8 |
| utf8_icelandic_ci | utf8 | 193 | | Yes | 8 |
| utf8_latvian_ci | utf8 | 194 | | Yes | 8 |
| utf8_romanian_ci | utf8 | 195 | | Yes | 8 |
| utf8_slovenian_ci | utf8 | 196 | | Yes | 8 |
| utf8_polish_ci | utf8 | 197 | | Yes | 8 |
| utf8_estonian_ci | utf8 | 198 | | Yes | 8 |
| utf8_spanish_ci | utf8 | 199 | | Yes | 8 |
| utf8_swedish_ci | utf8 | 200 | | Yes | 8 |
| utf8_turkish_ci | utf8 | 201 | | Yes | 8 |
| utf8_czech_ci | utf8 | 202 | | Yes | 8 |
| utf8_danish_ci | utf8 | 203 | | Yes | 8 |
| utf8_lithuanian_ci | utf8 | 204 | | Yes | 8 |
| utf8_slovak_ci | utf8 | 205 | | Yes | 8 |
| utf8_spanish2_ci | utf8 | 206 | | Yes | 8 |
| utf8_roman_ci | utf8 | 207 | | Yes | 8 |
| utf8_persian_ci | utf8 | 208 | | Yes | 8 |
| utf8_esperanto_ci | utf8 | 209 | | Yes | 8 |
| utf8_hungarian_ci | utf8 | 210 | | Yes | 8 |
| utf8_sinhala_ci | utf8 | 211 | | Yes | 8 |
| utf8_german2_ci | utf8 | 212 | | Yes | 8 |
| utf8_croatian_ci | utf8 | 213 | | Yes | 8 |
| utf8_unicode_520_ci | utf8 | 214 | | Yes | 8 |
| utf8_vietnamese_ci | utf8 | 215 | | Yes | 8 |
| utf8_general_mysql500_ci | utf8 | 223 | | Yes | 1 |
| utf8_general_ci | utf8 | 45 | Yes | Yes | 1 |
| utf8_bin | utf8 | 46 | | Yes | 1 |
| utf8_bin | utf8 | 224 | | Yes | 8 |
| utf8_icelandic_ci | utf8 | 225 | | Yes | 8 |
| utf8_latvian_ci | utf8 | 226 | | Yes | 8 |
| utf8_romanian_ci | utf8 | 227 | | Yes | 8 |
| utf8_slovenian_ci | utf8 | 228 | | Yes | 8 |
| utf8_polish_ci | utf8 | 229 | | Yes | 8 |
| utf8_estonian_ci | utf8 | 230 | | Yes | 8 |
| utf8_spanish_ci | utf8 | 231 | | Yes | 8 |
| utf8_swedish_ci | utf8 | 232 | | Yes | 8 |
| utf8_turkish_ci | utf8 | 233 | | Yes | 8 |
| utf8_czech_ci | utf8 | 234 | | Yes | 8 |
| utf8_danish_ci | utf8 | 235 | | Yes | 8 |
| utf8_lithuanian_ci | utf8 | 236 | | Yes | 8 |
| utf8_slovak_ci | utf8 | 237 | | Yes | 8 |
| utf8_spanish2_ci | utf8 | 238 | | Yes | 8 |
| utf8_roman_ci | utf8 | 239 | | Yes | 8 |
| utf8_persian_ci | utf8 | 240 | | Yes | 8 |
| utf8_esperanto_ci | utf8 | 241 | | Yes | 8 |
| utf8_hungarian_ci | utf8 | 242 | | Yes | 8 |
| utf8_sinhala_ci | utf8 | 243 | | Yes | 8 |
| utf8_german2_ci | utf8 | 244 | | Yes | 8 |
| utf8_croatian_ci | utf8 | 245 | | Yes | 8 |
| utf8_unicode_520_ci | utf8 | 246 | | Yes | 8 |
| utf8_vietnamese_ci | utf8 | 247 | | Yes | 8 |
+--------------------------+---------+-----+---------+----------+---------+
53 rows in set (0.00 sec) mysql> -- 9、插入测试数据
-- use db2019;
insert into tbl_test(name) values('aaa');
insert into tbl_test(name) values('bbb');
insert into tbl_test(name) values('AAA');
insert into tbl_test(name) values('BBB'); mysql> select * from tbl_test;
+----+------+
| id | name |
+----+------+
| 1 | aaa |
| 3 | AAA |
| 2 | bbb |
| 4 | BBB |
+----+------+
4 rows in set (0.00 sec) mysql> select * from tbl_test where name='aaa';
+----+------+
| id | name |
+----+------+
| 1 | aaa |
| 3 | AAA |
+----+------+
2 rows in set (0.00 sec) -- 10、默认情况下,不区分大小写,修改成大小写敏感
-- alter database db2019 character set=utf8;
alter database db2019 character set=utf8 collate=utf8_bin; -- alter table tbl_test convert to character set utf8 ;
alter table tbl_test convert to character set utf8 collate utf8_bin; -- 只修改这个即可实现区分大小写
-- alter table tbl_test change name name varchar(20) character set utf8 collate utf8_general_ci not null;
-- alter table tbl_test modify name varchar(20) character set utf8 collate utf8_general_ci not null;
alter table tbl_test change name name varchar(20) character set utf8 collate utf8_bin not null;
alter table tbl_test modify name varchar(20) character set utf8 collate utf8_bin not null; mysql> alter database db2019 character set=utf8 collate=utf8_bin;
Query OK, 1 row affected (0.00 sec) mysql> show create database db2019;
+----------+----------------------------------------------------------------------------------+
| Database | Create Database |
+----------+----------------------------------------------------------------------------------+
| db2019 | CREATE DATABASE `db2019` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */ |
+----------+----------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select * from tbl_test where name='aaa';
+----+------+
| id | name |
+----+------+
| 1 | aaa |
| 3 | AAA |
+----+------+
2 rows in set (0.00 sec)
-- 此时只修改库级别的还不行,仍然还需要修改表级别的
mysql> alter table tbl_test convert to character set utf8 collate utf8_bin;
Query OK, 4 rows affected (0.08 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select * from tbl_test where name='aaa';
+----+------+
| id | name |
+----+------+
| 1 | aaa |
+----+------+
1 row in set (0.00 sec)
utf8的大小写敏感性测试及其修改方法的更多相关文章
- utf8mb4的大小写敏感性测试及其修改方法
utf8mb4的大小写敏感性测试及其修改方法 utf8mb4_ unicode_ ci 与 utf8mb4_ general_ ci 如何选择字符除了需要存储,还需要排序或比较大小,涉及到与编码字符集 ...
- mysql8.0数据库忘记密码时进行修改方法
最近安装mysql8.0数据库,用以前的修改mysql方法,没有成功,所以参考网上前辈的做法,自己重新整理了下忘记密码时进行修改方法 1.安装mysql8.0后发现,在安装目中,是没有my.ini 和 ...
- web测试要点、方法_web端测试大全总结
一.功能测试 1.1链接测试 链接是web应用系统的一个很重要的特征,主要是用于页面之间切换跳转,指导用户去一些不知道地址的页面的主要手段,链接测试一般关注三点: 1)链接是否按照既定指示那样,确实链 ...
- BluetoothChat用于蓝牙串口通信的修改方法
本人最近在研究嵌入式的串口通信,任务是要写一个手机端的遥控器用来遥控双轮平衡小车.界面只用了一个小时就写好了,重要的问题是如何与板子所带的SPP-CA蓝牙模块进行通信. SPP-CA模块自带代码,在这 ...
- as关键词还有另外一个用途,那就是修改 方法 的访问控制
PHP是单继承的语言,在PHP 5.4 Traits出现之前,PHP的类无法同时从两个基类继承属性或方法.php的Traits和Go语言的组合功能类似,通过在类中使用use关键字声明要组合的Trait ...
- 命令窗口修改编码,CMD编码修改方法
cmd中的编码方式为ANSI,若中文不是此编码方式则会出现乱码.作为程序员,会经常使用命令窗口查看执行日志,但是有时编码格式不对,大部分都是UTF8,在网上搜索了不少方法,很多没什么用,在这里教一个具 ...
- debug运行可以,release运行报错的原因及修改方法
通常我们开发的程序有2种模式:Debug模式和Release模式在Debug模式下,编译器会记录很多调试信息,也可以加入很多测试代码,方便我们程序员测试,以及出现bug时的分析解决Release模式下 ...
- dos命令窗口修改编码,CMD编码修改方法
dos命令窗口修改编码,CMD编码修改方法 第一步,打开命令窗口有两种方法第一种:可以点击左下角的开始按钮,在运行里面输入CMD,然后敲回车2第二种:组合键WIN+R键,组合键后就会弹出窗口,然后输入 ...
- nose测试中修改nose_html_reporting插件,使生成的html报告加入显示截图功能
使用nose框架在测试WEB UI自动化时,使用了第三方插件nose-html-reporting,来生成HTML报告,nose-html-reporting具体使用参见管网https://pypi. ...
随机推荐
- 从0开始的Python学习003序列
sequence 序列 序列是一组有顺序数据的集合.不知道怎么说明更贴切,因为python的创建变量是不用定义类型,所以在序列中(因为有序我先把它看作是一个有序数组)的元素也不会被类型限制. 序列可以 ...
- javaweb学习--jsp
阅读电子书<Java Web从入门到精通>密码:461c,学习JavaWeb基础知识.由于本人已有html基础,所以直接略过前面部分,进入jsp学习 jsp页面添加库引用,引入项目文件 引 ...
- wxPython树控件
1.树控件 树(tree)是一种通过层次结构展示信息的控件,如下图所示是树控件示例,左窗口中是树控件,在wxPython中树控件类是wx.TreeCtrl. wx.TreeCtrl中一个常用的方法有: ...
- vue 用less
https://blog.csdn.net/u013746071/article/details/79655042
- 解决IntelliJ IDEA 创建Maven项目速度慢问题
IntelliJ IDEA 创建maven项目速度很慢,甚至卡住不动了. 原因 IDEA根据maven archetype的本质,其实是执行mvn archetype:generate命令,该命令执行 ...
- audio元素和video元素在ios和andriod中无法自动播放
原因: 因为各大浏览器都为了节省流量,做出了优化,在用户没有行为动作时(交互)不予许自动播放: /音频,写法一 <audio src="music/bg.mp3" autop ...
- 浏览器各个版本和系统(chrome/safari/edge/qq/360)
浏览器对象: let userAgent = navigator.userAgent.toLowerCase()console.log(userAgent) Edge: mozilla/5.0 (wi ...
- [LeetCode] 5. 最长回文子串
题目链接:https://leetcode-cn.com/problems/longest-palindromic-substring/ 题目描述: 给定一个字符串 s,找到 s 中最长的回文子串.你 ...
- Linux实战教学笔记51:Zabbix监控平台3.2.4(三)生产环境案例
https://www.cnblogs.com/chensiqiqi/p/9162986.html 一,Zabbix生产环境监测案例概述 1.1 项目规划 [x] :主机分组 交换机 Nginx To ...
- Python排序算法——冒泡排序
有趣的事,Python永远不会缺席! 如需转发,请注明出处:小婷儿的python https://www.cnblogs.com/xxtalhr/p/10786904.html 一.冒泡排序(Bubb ...