Windows下 MySQL大小写敏感配置

zoerywzhou@163.com

作者:Zhouwan

2017-3-27

最近在window系统下 操作Linux系统下创建的数据库,发现有些不对劲,比较了半天才发现是大小写敏感的问题造成的。网上搜索了一下,解决了这个问题,做个简明扼要的记录。

按照网上的说明:

WINDOWS:

编辑MySQL安装目录下的my.ini 文件,在[mysqld]节下 添加 lower_case_table_names=0 (备注:为0时大小写敏感,为1时大小写不敏感,默认为1),可以实现MySql按照建表Sql语句的大小写状态来定义表名。

具体操作的时候会发现,理论和实践总是有差异的:

我的MySQL安装路径为:C:\Program Files\MySQL\MySQL Server 5.7\bin(网上有的说my.ini配置文件在这个文件夹下)

但是my.ini所在的文件路径为:C:\ProgramData\MySQL\MySQL Server 5.7\my.ini

然后在[mysqld]节下 添加 lower_case_table_names=0。

配置好文件了,去试一下咋样。

然后,还没重启系统进行测试,在另一个博文里看到了官方手册的网址链接,按捺不住好奇心去看一下。发现上面的这个配置是不可行的(具体分析见下面的划重点)

可能出现的错误可参见这篇求助博文的内容以及下面的讨论:http://bbs.csdn.net/topics/391860287

(在官网说明的基础上加上我的独家中文解说 O(∩_∩)O~英文好的同学最好直接看英文文档,说的比较清楚)

How table and database names are stored on disk and used in MySQL is affected by the lower_case_table_names system variable, which you can set when starting mysqld. lower_case_table_names can take the values shown in the following table. This variable does not affect case sensitivity of trigger identifiers. OnUnix, the default value of lower_case_table_names is 0. On Windows, the default value is 1. On OS X, the default value is2.

PS:mac OS(2012年前称Mac OS X,2012年-2016年称OS X)

ValueMeaning

0

Table and database names are stored on disk using the lettercase specified in the CREATE TABLE or CREATE 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 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 or CREATE 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 for lower_case_table_names=1.

(总结:存储时大小写敏感,按照建表时指定的写法;查询时都转换为小写字母)

1、单平台:If you are using MySQL on only one platform, you do not normally have to change the lower_case_table_names variable from its default value.

2、跨平台:However, you may encounter difficulties if you want totransfer tables between platforms that differ in file system case sensitivity. For example, on Unix, you can have two different tables named my_table and MY_TABLE, but on Windows these two names are considered identical. To avoid data transfer problems arising from lettercase of database or table names, you have two options:(跨平台的MySQL大小写敏感解决方案在此!!!看看官网怎么说~)

Use lower_case_table_names=1 on all systems. The main disadvantage with this is that when you use SHOW TABLES or SHOW DATABASES, you do not see the names in their original lettercase.

Use lower_case_table_names=0on Unix and lower_case_table_names=2on Windows. This preserves the lettercase of database and table names. The disadvantage of this is that you must ensure that your statements always refer to your database and table names with the correct lettercase on Windows. If you transfer your statements to Unix, where lettercase is significant, they do not work if the lettercase is incorrect.

Exception: If you are usingInnoDB tables and you are trying to avoid these data transfer problems, you should set lower_case_table_names to1 on all platforms to force names to be converted to lowercase.

有点复杂。。。本来看懂了的,又出来了个Exception。。。本来愉悦的心情又down了,因为我的table就是InnoDB,看了半天想去配置文件大展身手来着。。。

好吧,那就先不管跨不跨平台了,也不管配置文件my.ini了。直接上手使用的话,想要区别大小写,可以在查询语句的时候加上Binary,具体实现如下:

(此段文字的参考博文:http://www.cnblogs.com/softidea/p/6047766.html。在此博文的基础上,内容已大幅度精简提炼)

参考方案:

1、在建表时指定大小写敏感:

MySql默认查询是不区分大小写的,如果需要区分他,必须在建表的时候,Binary标示敏感的属性.

CREATE TABLE NAME(

name VARCHAR(10)  BINARY);

2、 在查询条件的字段名前 加上binary:

在SQL语句中实现 SELECT * FROM TABLE NAME WHEREBINARY name=‘Clip‘;

3、 设置字符集使其大小写敏感:

utf8_general_ci --不区分大小写

utf8_bin--区分大小写

【设置collate(校对) 。 collate规则:

*_bin: 表示的是binary case sensitive collation,也就是说是区分大小写的

*_cs: case sensitive collation,区分大小写

*_ci: case insensitive collation,不区分大小写 】

4、可以修改该字段的collation 为 binary

比如:

ALTER TABLE TABLENAME MODIFY COLUMN COLUMNNAME VARCHAR(50) BINARY CHARACTERSET utf8  COLLATE utf8_bin DEFAULT NULL;

mysql 大小写 if_【已解决】Windows下 MySQL大小写敏感 解决方案及分析相关推荐

  1. mac mysql密码错误_解决mac 下mysql安装后root用户登录密码错误问题

    使用的mac OS 10.11  安装mysql后访问root/root用户失败,网上找了一些解决办法,下面记录下解决方法方便以后自己查询 概述(看懂下面就不用看了): 停服务:sudo /usr/l ...

  2. mysql如何下载msi_2、Windows下MySQL数据库下载与安装详细教程 MSI方式

    做者:叁念mysql 写在前言:本文篇幅比较长,可是整体分为三大部分:下载部分.安装部分.环境配置与测试部分 :读者能够自行选择阅读web 1.下载部分 MySQL数据库下载与安装详细教程sql 1. ...

  3. mysql克隆master_科学网—Windows下Mysql的Master-Slave Replication主从复制配置 - 刘洋的博文...

    最近做mysql的主从服务器(master-slave)复制,折腾了半天才搞定,记录一下完整的过程:就用局域网数据替代我的操作,比如:slaveip为从服务器ip,192.168.2.3:master ...

  4. windows下mysql和linux下mysql主从配置

    1. linux下mysql安装版本5.6   windows下mysql版本5.7  不要问我为什么版本不一致  就是想这么搞 2. linux为主服务器   windows为从服务器 3.找到li ...

  5. Windows下MySQL+PHP5的配置与phpBB2论坛的架设

    我们在 Windows下Apache和PHP5的安装和配置一文中谈到了Apache+PHP5的安装配置问题,但是在大多数的情况下,我们不仅需要这样的配置,还要需要数据库的支持.在这里我们以MySQL为 ...

  6. win上mysql忘记root密码_MySQL数据库之windows下mysql忘记root密码的解决方法

    本文主要向大家介绍了MySQL数据库之windows下mysql忘记root密码的解决方法 ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助. 方法一: 1.在DOS窗口下输入net ...

  7. 【异常处理】解决Windows下access denied for user ‘root‘@‘localhost‘(using password:YES)的mysql启动问题

    [异常处理]解决Windows下access denied for user 'root'@'localhost'(using password:YES)的mysql启动问题 **原因:**可能是密码 ...

  8. 解决Windows安装MySQL时出现msvcr120.dll文件丢失问题(完美解决)

    解决Windows安装MySQL时出现msvcr120.dll文件丢失问题(完美解决,建议直接看:方法3) 1.安装MySQL时时,出现如下问题: 解决方式如下: 方法1:网上下载msvcr120.d ...

  9. windows 下mysql的安装于使用(启动、关闭)

    1.下载Windows (x86, 64-bit), ZIP Archive解压: 2.双击在bin目录里的mysqld.exe dos窗体一闪就没了,这时netstat -an发现port3306已 ...

最新文章

  1. 使用NVIDIA GRID vPC支持视频会议和算力工具
  2. 【总结】有三AI所有GAN相关学习资料汇总,有图文、视频、代码实战等......
  3. 9 HTML5之表单
  4. 什么是Sentinel?它能做什么
  5. c# 给文件/文件夹 管理用户权限
  6. IDA来远程调试Linux程序
  7. windows 常用系统变量
  8. java 注解应用技巧_改善Java应用程序性能的快速技巧
  9. tnsnames.ora配置未生效_1分钟了解网络交换机的6种命令配置模式
  10. 天津科技大学计算机合资办学,天津科技大学计算机科学与信息工程学院介绍
  11. [导入]C#实现WEB浏览器
  12. sublime 插件安装;sublime的 babel、sublime-jsfmt插件
  13. Linux 命令汇总!【珍藏版】
  14. Linux中kobject的作用,Linux设备驱动模型-- 数据结构Kset/KObject
  15. 洛谷——P1008 [NOIP1998 普及组] 三连击
  16. vs2019建立web工程_自动化工程师的C#之路(1)
  17. java按钮禁用和启用_在浏览器中禁用(或启用)Java插件
  18. java ftp 上传下载
  19. 无U盘 安装纯净win7系统
  20. USB与串口的区别简要总结

热门文章

  1. ASP.NET Core文件上传与下载(多种上传方式)
  2. .net ef core 领域设计代码转换(上篇)
  3. 面向 Visual Studio 开发者的 Git 内部源代码
  4. ASP.NET Core 导入导出Excel xlsx 文件
  5. 清除谷歌浏览器的dns缓存
  6. 利用Excel VBA批量计算气象数据多个台站多年来春季和冬季降水量和平均气温
  7. C语言试题六十七之请编写函数实现水仙花数
  8. C和指针之数组编程练习8(8皇后问题)
  9. LeetCode之Single Number
  10. ios之Xcode工程中添加文件常用快捷键