【已解决】Windows下 MySQL大小写敏感 解决方案及分析
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了【已解决】Windows下 MySQL大小写敏感 解决方案及分析,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4652字,纯文字阅读大概需要7分钟。
内容图文
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 Unix, the default value of lower_case_table_names
is 0. On Windows, the default value is 1. On OS X, the default value is 2.
PS:mac OS(2012年前称Mac OS X,2012年-2016年称OS X)
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=1
on all systems. The main disadvantage with this is that when you useSHOW TABLES
orSHOW DATABASES
, you do not see the names in their original lettercase. -
Use
lower_case_table_names=0
on Unix andlower_case_table_names=2
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
InnoDB
tables and you are trying to avoid these data transfer problems, you should setlower_case_table_names
to 1 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 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;
【已解决】Windows下 MySQL大小写敏感 解决方案及分析
标签:网址链接 指定 target trigger 问题 配置文件 好的 gen tle
本文系统来源:http://www.cnblogs.com/swje/p/6628315.html
内容总结
以上是互联网集市为您收集整理的【已解决】Windows下 MySQL大小写敏感 解决方案及分析全部内容,希望文章能够帮你解决【已解决】Windows下 MySQL大小写敏感 解决方案及分析所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。