天天看點

設定mysql表名大小寫不敏感

在跨平台的程式設計中要注意到mysql的一些系統變量在windows和linux上的預設值是不同的, 比如mysql表名稱的大小寫變量.

在windows上lower_case_table_names變量的預設值為1; 在linux上為0; 在mac os上為2; 

該變量值的詳細定義如下:

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

lower_case_table_names=1

.

如果想在linux環境中想設定表名為大小寫不敏感, 那麼可以通過如下的指令:

mysqld --SET-lower_case_table_names=1;

或者在mysql server的配置檔案中添加配置項:

vi /etc/my.cnf

[plain] view plaincopy

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

iefreer

設定mysql表名大小寫不敏感
上一篇: rb