天天看點

mysql 表名大小寫敏感處理 lower_case_table_names

到mysql資料庫下查詢表時,差點沒被表名的大小寫搞死。

到官網檢視文檔,可以通過參數控制

# vi /etc/my.cnf
[mysqld]
lower_case_table_names=1             

官網的描述如下

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.

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

0:使用 CREATE TABLE 或 CREATE DATABASE 語句中指定的字母将表和資料庫名稱存儲在磁盤上。名稱比較區分大小寫。如果在具有不區分大小寫的檔案名(如Windows或OSX)的系統上運作MySQL,則不應将此變量設定為0。如果在不區分大小寫的檔案系統中強制此變量為-小寫表名=0,并使用不同的字母案例通路MyISAM表名,則可能會導緻索引損壞。

1:表名以小寫形式存儲在磁盤上,名稱比較不區分大小寫.MySQL在存儲和查找時将所有表名轉換為小寫。此行為也适用于資料庫名稱和表别名。

2:使用 CREATE TABLE 或 CREATE DATABASE 語句中指定的字母将表和資料庫名稱存儲在磁盤上,但MySQL**在查找時将它們轉換為小寫。名稱比較不區分大小寫**。這隻在不區分大小寫的檔案系統上工作!InnoDB表名以小寫形式存儲,對于LOWER_CASE_TABLE_NAMES=1。