MYSQL如何设置大小写敏感

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYSQL如何设置大小写敏感相关的知识,希望对你有一定的参考价值。

参考技术A mysql数据库名和表名的大小写敏感说明
:mysql中的数据库名和表名和操作系统有关,在windows操作系统中,不区分大小写,在unix
,linux操作系统中,是区分大小写的。其实可以到mysql存放数据的data目录下进行查看,可以知道其实一个数据库是对应表,一张表是对应一个
表名+.frm的文件

由于在windows操作系统中,文件名和目录名是不区分大小写的,
所以mysql数据库名和表名在windows下是大小写不敏感的,而unix,linux则不然。
下面是mysqlmanual原文说明:
in
mysql,
databases
and
tables
correspond
to
directories
and
files
within
those
directories.
consequently,
the
case
sensitivity
of
the
underlying
operating
system
determines
the
case
sensitivity
of
database
and
table
names.
this
means
database
and
table
names
are
case
sensitive
in
unix
and
case
insensitive
in
windows.
列名的大小写说明:

mysql数据库如何设置表名大小写不敏感?

转自:https://blog.csdn.net/iefreer/article/details/8313839

在跨平台的程序设计中要注意到mysql的一些系统变量在windows和linux上的缺省值是不同的, 比如mysql表名称的大小写变量.

在windows上lower_case_table_names变量的缺省值为1; 在linux上为0; 在mac os上为2; 

该变量值的详细定义如下:

 

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 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 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 forlower_case_table_names=1.

 

如果想在linux环境中想设置表名为大小写不敏感, 那么可以通过如下的命令:

mysqld --SET-lower_case_table_names=1;

或者在mysql server的配置文件中添加配置项:

vi /etc/my.cnf

 

[plain] view plain copy
 
    1. # The MySQL server  
    2. [mysqld]  
    3. set-variable=lower_case_table_names=1  

以上是关于MYSQL如何设置大小写敏感的主要内容,如果未能解决你的问题,请参考以下文章

mysql数据库如何设置表名大小写不敏感?

mysql设置大小写敏感

MySQL中大小写敏感涉及的属性以及查询如何区分大小写

mysql 大小写取消敏感设置

windows下安装Mysql8,表名无法设置成大小写敏感的解决

Mysql设置大小写敏感