zoukankan      html  css  js  c++  java
  • 修改mysql数据的字符集校验规则使其区分大小写

    mysql 使用utf8字符集默认的校验规则collate为utf8_general_ci,不区分数据的大小写

    测试如下

    13:50:04[test](;)> alter table test add col1 varchar(25) character set utf8 collate utf8_bin;
    Query OK, 0 rows affected (0.16 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
    13:51:43[test](;)> update test set col1='BBc' where name='bbc';
    Query OK, 1 row affected (0.11 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    13:52:10[test](;)> select * from test;
    +------+------+
    | name | col1 |
    +------+------+
    | BBC  | BBc  |
    +------+------+
    1 row in set (0.00 sec)
    
    13:52:17[test](;)> select * from test where col1='bbc';
    Empty set (0.00 sec)
    
    13:52:36[test](;)> alter table test modify name varchar(25) character set utf8 collate utf8_bin;
    Query OK, 1 row affected (0.14 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    13:53:26[test](;)> select * from test where name='bbc';    
    Empty set (0.00 sec)
    13:53:32[test](;)> alter table test modify name varchar(25) character set utf8 collate utf8_general_ci;
    Query OK, 1 row affected (0.14 sec)
    Records: 1  Duplicates: 0  Warnings: 0
    
    14:06:26[test](;)> select * from test where name='bbc';
    +------+------+
    | name | col1 |
    +------+------+
    | BBC  | BBc  |
    +------+------+
    1 row in set (0.00 sec)

    修改数据库和表的字符集对已存入的和后来插入的数据都无影响,数据的collate依然是默认的

    alter table collate_ DEFAULT CHARSET=utf8 collate=utf8_bin;
    alter database test default COLLATE=utf8_bin;

    修改相关变量不起效,变更字段的collate才奏效

    
    
    14:09:00[(none)](;)> show variables like '%coll%';
    +----------------------+----------+
    | Variable_name        | Value    |
    +----------------------+----------+
    | collation_connection | utf8_bin |
    | collation_database   | utf8_bin |
    | collation_server     | utf8_bin |
    +----------------------+----------+
    
    
    
     
  • 相关阅读:
    CAST和CONVERT
    #pragma 预处理指令详解
    Android系统移植主要事项
    Java动态绑定机制的内幕
    Java接口和抽象类用法总结
    Android工程的编译过程
    点击按钮,并且实现增加一个按钮的效果 (附效果图)
    iOS-设置导航栏"返回"按钮 (附效果图)
    常用代码整理(重要)
    NSTimer 的暂停与恢复运行。
  • 原文地址:https://www.cnblogs.com/Bccd/p/8118538.html
Copyright © 2011-2022 走看看