mysql表名大小写敏感

在ubuntu下安装的mysql版本是 5.6.25-0ubuntu1 mysql

linux下的mysql的表名是大小写敏范的。而在在windows下安装的mysql是大小写不敏感的。linux

缘由是由于lower_case_table_names该属性在linux下默认为0,windows下默认为1sql

0---大小写敏感ubuntu

1---大小写不敏感windows

因此经过修改mysql的my.cnf的配置,既能够达到大小写不敏感.app

linux下修改my.cnf(若是是ubuntu的版本,不存在/ect/my.cnf而是存在于,/ect/mysql/my.cnf)来修改该配置:this

在[mysqld]组中,添加以下语句:rest

[mysqld]
lower_case_table_names = 1

而后重启 service mysql restart便可。code

 

因为以前本人建了一张EMP的表(在lower_case_table_names=0的时候):ci

CREATE TABLE EMP (
    ENAME VARCHAR(10),
    HIREDATE DATE,
    SAL DECIMAL(10,2)
);

是大写的表名。在修改配置以后,大小写不敏感了。

使用以下sql语句均报错:

DESC emp; 
DESC EMP;

均报一样的错误:

[Err] 1146 - Table 'test.emp' doesn't exist

按正常来讲,若是DESC EMP;应该报: 

[Err] 1146 - Table 'test.EMP' doesn't exist

才对的,可是,二者倒是报一样的错误。

而后查看文档:

Value   Meaning  
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.

能够看出

0是严格按找字母大小写查找

2是经过把大写转换成小写再进行查询(前提是大小写不敏感)。全部在已经存在大写的表时,转换成小写时,就找不到原来表,表名是EMP,可是更改配置后,查询表名的时候查找名称为emp的表,故而报[Err] 1146 - Table 'test.emp' doesn't exist,

经过把lower_case_table_names调节为0,而后将表名改回小写,而后,再调节回1.问题便可解决。

相关文章
相关标签/搜索