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. 黑帽么metasploit

    .Metasploit框架介绍Metasploit升级更新 Metasploit端口扫描 Metasploit SMB 获取系统信息 Metasploit 服务识别 Metasploit 密码嗅探 M ...

  2. linux 安装Gauss09 GaussView

  3. 成都IT公司面经及公司评价

    从2015年年底到2016年初找了几个月工作,面了大大小小若干公司,有很不错的公司,也有很多坑公司,与君共勉. 1.科大讯飞 地址:成都分公司位于天府软件园E区,占一层楼.面积挺大.公司装修风格很舒服 ...

  4. HBase常见问题答疑解惑【持续更新中】

    HBase常见问题答疑解惑[持续更新中] 本文对HBase开发及使用过程中遇到过的常见问题进行梳理总结,希望能解答新加入的HBaser们的一些疑惑. 1. HTable线程安全吗? HTable不是线 ...

  5. MySQL的保留字查询

    ADD ALL ALTER ANALYZE AND AS ASC AUTO_INCREMENT BDB BEFORE BERKELEYDB BETWEEN BIGINT BINARY BLOB BOT ...

  6. 4、js内置函数

    前言:上一篇我介绍了函数的基本概念,和一些简单的Demo.其实很多函数是js内置的,我们无需自己去写,直接拿过来用即可.内置函数分为全局函数和js内置对象的函数区别:全局函数不属于任何一个内置对象.理 ...

  7. html5 article标签举例

    <article> 是html5中引入的新标签可以实现正向反向列表排序功能 使用以前的html4进行列表排序,可以使用下列形式 <h1>Top Three Teams</ ...

  8. java 读取excel(Map结构)xls

    package com.sun.test; import java.io.FileInputStream;import java.io.FileNotFoundException;import jav ...

  9. CPU高问题排查

    双11大战开始了,这几天公司系统压测,CPU各种报警,于是找了篇关于CPU高问题排查的文章. 一个应用占用CPU很高,除了确实是计算密集型应用之外,通常原因都是出现了死循环. (友情提示:本博文章欢迎 ...

  10. 一步一步学EF系列 【7、结合IOC ,Repository,UnitOfWork来完成框架的搭建】

    前言 距离上一篇已经有段时间了,最近这段时间赶上新项目开发,一直没有时间来写.之前的几篇文章,主要把EF的基础都讲了一遍,这批文章就来个实战篇. 个人在学习过程中参考博客: Entity Framew ...