【已解决】Windows下 MySQL大小写敏感 解决方案及分析
Windows下 MySQL大小写敏感配置
zoerywzhou@163.com
http://www.cnblogs.com/swje/
作者: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。
配置好文件了,去试一下咋样。
然后,还没重启系统进行测试,在另一个博文里看到了官方手册的网址链接,按捺不住好奇心去看一下。发现上面的这个配置是不可行的(具体分析见下面的划重点)
MySQL官网手册-大小写敏感说明:
(在官网说明的基础上加上我的独家中文解说 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. On. On . On .
| Value | Meaning |
|---|---|
0 |
Table and database names are stored on disk using the lettercase specified in the (总结:存储和查询的时候都大小写敏感,都要是按照建表时指定的写法) 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 |
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 (总结:存储时大小写敏感,按照建表时指定的写法;查询时都转换为小写字母) |
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 to transfer 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=1on all systems. The main disadvantage with this is that when you useSHOW TABLESorSHOW DATABASES, you do not see the names in their original lettercase.Use
lower_case_table_names=on 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 using
InnoDBtables and you are trying to avoid these data transfer problems, you should setlower_case_table_namesto 1 on all platforms to force names to be converted to lowercase.
有点复杂。。。本来看懂了的,又出来了个Exception。。。本来愉悦的心情又down了,因为我的table就是InnoDB,看了半天想去配置文件大展身手来着。。。
好吧,那就先不管跨不跨平台了,也不管配置文件my.ini了。直接上手使用的话,想要区别大小写,可以在查询语句的时候加上Binary,具体实现如下:
三个方案:
1、在建表时指定大小写敏感:
MySql默认查询是不区分大小写的,如果需要区分他,必须在建表的时候,Binary标示敏感的属性.
CREATE TABLE NAME(
name VARCHAR(10) BINARY);
2、 在查询条件的字段名前 加上binary:
在SQL语句中实现 SELECT * FROM TABLE NAME WHERE BINARY 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 CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL;
(此段文字的参考博文:http://www.cnblogs.com/softidea/p/6047766.html)
【已解决】Windows下 MySQL大小写敏感 解决方案及分析的更多相关文章
- 解决windows下MySQL表名大写自动变小写的问题
解决windows下MySQL表名大写自动变小写的问题 有些人可能会遇到在windows下,表名不能用大写字母, 即使使用了大写字母的建表语句,还是会被自动转成小写. 解决方法: 打开 My ...
- 解决windows 下 mysql命令行导入备份文件 查询时乱码的问题
Mysql导入乱码,一般在命令行会遇到.下面说的是命令行的情况下解决乱码问题: 方法一: 通过增加参数 –default-character-set = utf8 解决乱码问题 mysql -uroo ...
- 解决Windows下mysql无法启动1067错误
解决过程 查看服务发现mysql未启动 用cmd命令行启动提示启动失败 错误代码1067 打开时间查看器发现mysql错误记录信息为Fatal error: Can't open and lock ...
- 解决windows 下mysql 表名自动转成小写的问题
由于web用的是mvc,数据库用的是mysql.为了方便开发,在windows7下面也安装了个mysql,今天在创建表的时候,遇到了个棘手的问题.所有的表名都转成了小写,这不是我要的,作为处女座,是不 ...
- [已解决]windows下python3.x与python2.7共存版本pip使用报错问题
> 由于最近要更新插件,突然发现没法使用pip来安装升级插件,查了一圈才找到解决办法,特记录在此,便于其它人查询. 报错信息如下: Fatal error in launcher: Unable ...
- [已解决] windows 下 git 免输密码
在 .git/config 里面加上这句话即 [credential] helper = store 原文地址:http://www.cnblogs.com/gifisan/p/5829578.htm ...
- MySQL 5.7 Command Line Client输入密码后闪退和windows下mysql忘记root密码的解决办法
MySQL 5.7 Command Line Client输入密码后闪退的问题: 问题分析: 1.查看mysql command line client默认执行的一些参数.方法:开始->所有程序 ...
- Windows下mysql忘记密码的解决方法
Windows下mysql忘记密码的解决方法 mysql5.0 http://www.jb51.net/article/21984.htm方法一: 1.在DOS窗口下输入 net stop mysql ...
- 解决windows下的mysql匿名登陆无法使用mysql数据库的问题
原文:解决windows下的mysql匿名登陆无法使用mysql数据库的问题 我在windows下安装了mysql,但是不用密码就能登进去,而root明明是有密码的,我用select user()命令 ...
随机推荐
- python中文编码问题深入分析(一):字符编码基础
背景:笔者作为一名刚接触python语言的新手,在实际的项目中,遇到过一些中文编码问题,初次遇到这些问题的时候,刚开始显得有些手足无措,也不知从何查起.常言道:有问题,找度娘!当我打开www.baid ...
- java中关于转义字符的一个bug
在java中,你可以定义 char c = '\u4f60'; char m = '\u0045'; char e = '\u554a'; 这样的字面量,例如: System.out.println( ...
- git链接GitHub命令及基本操作
Git是一款不错的代码管理工具,下面引用百科的一段话: Git是用于Linux内核开发的版本控制工具.与CVS.Subversion一类的集中式版本控制工具不同,它采用了分布式版本库的作法,不需要服 ...
- [学习心得][Introduction to ASP.NET Core 1.0]3-2 ASP.NET Core and MVC Pattern
We need SMART Models, THIN Controllers, and DUMB Views. VeryBeginning 要使用MVC,要先将MVC服务加到程序中去 Nuget包里添 ...
- 查看hive中某个表中的数据、表结构及所在路径
查看hive中action_data_myisam表中的数据.表结构及所在路径 1.客户端进入hive环境:hive 2.查看表数据,鉴于数据量大,这里只显示前五条:select * from act ...
- 【转】Jqgrid学习之ColModel API
ColModel 是jqGrid里最重要的一个属性,设置表格列的属性. 属性 数据类型 备注 默认值 align string left, center, right. left classes st ...
- 每天一个linux命令(49)--diff命令
diff 命令是 Linux 上非常重要的工具,用于比较文件的内容,特别是比较两个版本不同的文件以找到改动的地方.diff 在命令行中打印每一个行的改动.最新版本的diff还支持二进制文件,diff ...
- 卷积神经网络(CNN)前向传播算法
在卷积神经网络(CNN)模型结构中,我们对CNN的模型结构做了总结,这里我们就在CNN的模型基础上,看看CNN的前向传播算法是什么样子的.重点会和传统的DNN比较讨论. 1. 回顾CNN的结构 在上一 ...
- 禁止Linux系统被 ping
echo "net.ipv4.icmp_echo_ignore_all=1" >> /etc/sysctl.conf sysctl -p 生效 开启ping功能: 删除 ...
- 【开源.NET】轻量级内容管理框架Grissom.CMS(第三篇解析配置文件和数据以转换成 sql)
该篇是 Grissom.CMS 框架系列文章的第三篇, 主要介绍框架用到的核心库 EasyJsonToSql, 把标准的配置文件和数据结构解析成可执行的 sql. 该框架能实现自动化增删改查得益于 E ...