MYSQL在默认的情况下查询是不区分大小写的,例如: 
 
1
2
3
4
5
6
7
mysql> create table t1(
-> name varchar(10));
Query OK, 0 rows affected (0.09 sec)
 
mysql> insert into t1 values('you'),('You'),('YOU');
Query OK, 3 rows affected (0.05 sec)
Records: 3 Duplicates: 0 Warnings: 0
 
对这个表,缺省情况下,下面两个查询的结果是一样的: 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
mysql> select * from t1 where name = 'you';
+------+
| name |
+------+
| you |
| You |
| YOU |
+------+
3 rows in set (0.00 sec)
 
mysql> select * from t1 where name = 'YOU';
+------+
| name |
+------+
| you |
| You |
| YOU |
+------+
3 rows in set (0.00 sec)
 
如果想让MYSQL知道你输入的字母是大写还是小写的,修改表: 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
mysql> alter table t1 change name name varchar(10) binary;
Query OK, 3 rows affected (0.20 sec)
Records: 3 Duplicates: 0 Warnings: 0
 
 
mysql> select * from t1 where name = 'you';
+------+
| name |
+------+
| you |
+------+
1 row in set (0.00 sec)
 
mysql> select * from t1 where name = 'YOU';
+------+
| name |
+------+
| YOU |
+------+
1 row in set (0.00 sec)
如果你只是想在SQL语句中实现的话: 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mysql> select * from t1 where name = binary 'YOU';
+------+
| name |
+------+
| YOU |
+------+
1 row in set (0.02 sec)
 
mysql> select * from t1 where name = binary 'you';
+------+
| name |
+------+
| you |
+------+
1 row in set (0.00 sec)
 
如果不想这么麻烦而想服务一开启就让大小写一致的话: 
可以修改my.ini或者my.cnf 
1
2
3
[mysqld]
lower_case_table_names=1
(0:区分;1:不区分)
然后重启MYSQL服务。 
 
1
2
3
4
5
6
7
mysql> show variables like '%case_table%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| lower_case_table_names | 1 |
+------------------------+-------+
1 row in set (0.00 sec)
 
 

在跨平台的程序设计中要注意到mysql的一些系统变量在windows和linux上的缺省值是不同的, 比如mysql表名称的大小写变量.

在windows上lower_case_table_names变量的缺省值为1; 在linux上为0; 在mac os上为2;

该变量值的详细定义如下

Value Meaning
0 Table and database names are stored on disk using the lettercase specified in the CREATE TABLE orCREATE DATABASE statement. Name comparisons are case sensitive. You should not set this variable to 0 if you are running MySQL on a system that has case-insensitive file names (such as Windows or Mac OS X). If you force this variable to 0 with --lower-case-table-names=0 on a case-insensitive file system and access MyISAM tablenames using different lettercases, index corruption may result.
1 Table names are stored in lowercase on disk and name comparisons are not case sensitive. MySQL converts all table names to lowercase on storage and lookup. This behavior also applies to database names and table aliases.
2 Table and database names are stored on disk using the lettercase specified in the CREATE TABLE orCREATE DATABASE statement, but MySQL converts them to lowercase on lookup. Name comparisons are not case sensitive. This works only on file systems that are not case sensitive! InnoDB table names are stored in lowercase, as forlower_case_table_names=1.

MySQL数据表中内容大小写区分的设置的更多相关文章

  1. (转)MySQL数据表中带LIKE的字符匹配查询

    MySQL数据表中带LIKE的字符匹配查询 2014年07月15日09:56    百科369 MySQL数据表中带LIKE的字符匹配查询 LIKE关键字可以匹配字符串是否相等. 如果字段的值与指定的 ...

  2. 向mysql数据表中插入数据失败的原因

    1.案例代码: $sql1="insert into content(category,subject,content,username,release_date) values('{$ca ...

  3. Linux中MySQL忽略表中字段大小写

    linux 下,mysql 的表面默认是区分大小写的,windows 下默认不区分大小写,我们大多数在windows 下开发,之后迁移到linux(特别是带有Hibernate的工程),可以修改配置是 ...

  4. 删除Mysql数据表中多余的重复记录的sql语句

    数据表 sniper_tb 中存在主键 id,字段url,现需要在url字段上添加 unique,但由于url存在重复记录,导致添加失败. 如何删除表中多余的url重复记录,仅保持一条? 思路一 将 ...

  5. mysql 数据表中查找、删除重复记录

    为了性能考虑,在阅读之前提醒大家,如果有子查询,子查询查询到的数据最好不要超过总数据量的30%. 查询有重复数据的记录 select * from F group by a,b,c,d having ...

  6. 【转】MySQL数据表中记录不存在则插入,存在则更新

    mysql 记录不存在时插入在 MySQL 中,插入(insert)一条记录很简单,但是一些特殊应用,在插入记录前,需要检查这条记录是否已经存在,只有当记录不存在时才执行插入操作,本文介绍的就是这个问 ...

  7. 从mysql数据表中随机取出一条记录

    核心查找数据表代码: ; //此处的1就是取出数据的条数 但这样取数据网上有人说效率非常差的,那么要如何改进呢 搜索Google,网上基本上都是查询max(id) * rand()来随机获取数据. S ...

  8. c#读取MySQL数据表中的内容

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. 清空mysql数据表中的所有数据

    - 清空全部数据,不写日志,不可恢复,速度极快 truncate table_name;   -- 清空全部数据,写日志,数据可恢复,速度慢 delete from 表名     详情请查看区别

随机推荐

  1. 新手站长选择WordPress程序建站需要注意的8个问题

    文章出自:http://www.banwagongvps.com/119.html 如今我们不论是出于个人的兴趣爱好,还是出于我们希望通过搭建自己的网站获利的动机,入门级别的都变得非 常的简单,我们只 ...

  2. jquery无法为动态生成的元素添加点击事件的解决方法

    遇到 jquery无法为动态生成的元素添加点击事件,谷歌一下,整理一下解决方法如下: (<li>中间的元素是动态生成的), 现在想为<i>添加点击事件, 例子如下: <d ...

  3. Java 反射 分析类和对象

    Java 反射 分析类和对象 @author ixenos 摘要:优化程序启动策略.在运行时使用反射分析类的结构和对象 优化程序启动策略 在启动时,包含main方法的类被加载.它会加载所有它需要的类. ...

  4. ZUFE 1035 字符宽度编码(字符串)

    Time Limit: 1 Sec  Memory Limit: 128 MB Description 你的任务是编写一个程序实现简单的字符宽度编码方法.规则如下:将任何2~9个相同字符的序列编码成2 ...

  5. [ An Ac a Day ^_^ ] [kuangbin带你飞]专题四 最短路练习 POJ 2387 Til the Cows Come Home

    求1到N的最短路 注意有重边 跑一遍dijkstra就行 /* *********************************************** Author :Sun Yuefeng ...

  6. CALayer的隐式动画和显式动画

    隐式事务 任何对于CALayer属性的修改,都是隐式事务,都会有动画效果.这样的事务会在run-loop中被提交. - (void)viewDidLoad { //初始化一个layer,添加到主视图 ...

  7. urllib2 之info 学习

    之前介绍了根据old_url获取真实url的geturl的方法,而根据urlopen返回的应答对象的info方法可以获取服务器发送头部headers的内容,并且通过字典形式反馈出来,同样测试代码如下: ...

  8. ajax传递的数据类型json传递

    $(".del_goods").click(function(){ //删除选中的商品 var clear_data = [];//数组 $("input[name='c ...

  9. SQL 课程

    今天,我主要学习了数据库的基本查询,模糊查询.排序查询.聚合函数.计数和分组,以及数学函数.字符串函数.时间日期函数. create database lianxi0720gouse lianxi07 ...

  10. java实现线程的3中方式

    1.继承Thread类实现多线程继承Thread类的方法尽管被我列为一种多线程实现方式,但Thread本质上也是实现了Runnable接口的一个实例,它代表一个线程的实例,并且,启动线程的唯一方法就是 ...