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. IE8及以下不支持getElementByClassName的解决办法

    function getByClass(oParent, sClass){ var aEle=oParent.getElementsByTagName('*'); var aResult=[]; va ...

  2. Apache .htaccess语法之RewriteRule

    [说明]定义重写的规则[语法]RewriteRule Pattern rewritePattern [flags] # 开启 rewrite 功能 Options +FollowSymlinks Re ...

  3. phpMyAdmin 尝试连接到 MySQL 服务器,但服务器拒绝连接。

     phpMyAdmin 尝试连接到 MySQL 服务器,但服务器拒绝连接.您应该检查配置文件中的主机.用户名和密码,并确认这些信息与 MySQL 服务器管理员所给出的信息一致. 错误产生原因: 修改了 ...

  4. datables的基本操作

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  5. link 与 @import之对比

    页面中使用CSS的方式主要有3种:行内添加定义style属性值,页面头部内嵌调用和外面链接调用,其中外面引用有两种:link和@import.外部引用CSS两种方式link和@import的方式分别是 ...

  6. 第14天dbutils与案例

    第14天dbutils与案例 第14天dbutils与案例    1 1.    1.dbutils介绍    2 2.    2.dbutils快速入门    2 3.    3.dbutils A ...

  7. hdu1008

    //c++// #includeusing namespace std;int main(){int n,j,t,start;while (cin >> n,n){start =0;t = ...

  8. 实验--DHCP服务器搭建

    系统环境:CentOS PC1: 客户端1(克隆CentOS) PC2: 客户端2(克隆CentOS) Router: 模拟路由器(克隆CentOS)

  9. uhttpd配置文件分析

    文件位于 /etc/config/uhttpd. root@hbg:/etc/config# cat uhttpd config uhttpd 'main'        list listen_ht ...

  10. Marble 绘制线

    #include <QtGui/QApplication> #include <marble/MarbleWidget.h> #include <marble/GeoPa ...