在MySQL當(dāng)中,有可能遇到表名大小寫(xiě)敏感的問(wèn)題。其實(shí)這個(gè)跟平臺(tái)(操作系統(tǒng))有關(guān),也跟系統(tǒng)變量lower_case_table_names有關(guān)系。下面總結(jié)一下,有興趣可以查看官方文檔“Identifier Case Sensitivity”
In MySQL, databases correspond to directories within the data directory. Each table within a database corresponds to at least one file within the database directory (and possibly more, depending on the storage engine). Triggers also correspond to files. Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database, table, and trigger names. This means such names are not case-sensitive in Windows, but are case-sensitive in most varieties of Unix. One notable exception is macOS, which is Unix-based but uses a default file system type (HFS+) that is not case-sensitive. However, macOS also supports UFS volumes, which are case-sensitive just as on any Unix. See Section 1.8.1, “MySQL Extensions to Standard SQL”. Thelower_case_table_names system variable also affects how the server handles identifier case sensitivity, as described later in this section.
在 MySQL 中, 數(shù)據(jù)庫(kù)對(duì)應(yīng)于數(shù)據(jù)目錄中的目錄。數(shù)據(jù)庫(kù)中的每個(gè)表對(duì)應(yīng)于數(shù)據(jù)庫(kù)目錄中至少一個(gè)文件 (可能更多, 具體取決于存儲(chǔ)引擎)。觸發(fā)器也對(duì)應(yīng)于文件。因此, 底層操作系統(tǒng)的區(qū)分大小寫(xiě)在數(shù)據(jù)庫(kù)、表和觸發(fā)器名稱的大小寫(xiě)敏感度方面起著重要作用。這意味著這些名稱在 Windows 中不區(qū)分大小寫(xiě), 但在大多數(shù)類型的 Unix 中都是區(qū)分大小寫(xiě)的。一個(gè)顯著的例外是 macOS, 它是基于 Unix 的, 但使用的是不區(qū)分大小寫(xiě)的默認(rèn)文件系統(tǒng)類型 (HFS+)。但是, macOS 還支持 UFS 卷, 它們與任何 Unix 一樣都是區(qū)分大小寫(xiě)的。參見(jiàn)1.8.1 節(jié), “MySQL Extensions to Standard SQL“。lower_case_table_names 系統(tǒng)變量還影響服務(wù)器處理標(biāo)識(shí)符大小寫(xiě)靈敏度的方式, 如本節(jié)后面所述。
Linux系統(tǒng):
數(shù)據(jù)庫(kù)名與表名是嚴(yán)格區(qū)分大小寫(xiě)的;
表的別名是嚴(yán)格區(qū)分大小寫(xiě)的;
列名與列的別名在所有的情況下均是忽略大小寫(xiě)的;
變量名也是嚴(yán)格區(qū)分大小寫(xiě)的;
Windows系統(tǒng):
都不區(qū)分大小寫(xiě)
Mac OS下(非UFS卷):
都不區(qū)分大小寫(xiě)
注意事項(xiàng):列名、索引、存儲(chǔ)過(guò)程、事件名稱在任何平臺(tái)上都不區(qū)分大小寫(xiě),列別名也不區(qū)分大小寫(xiě)。
Notice:Column, index, stored routine, and event names are not case sensitive on any platform, nor are column aliases.
下面在測(cè)試環(huán)境為Red Hat Enterprise Linux Server release 5.7, MySQL 5.6.20:
| mysql> show variables like 'lower_case_table_names';+------------------------+-------+| Variable_name | Value |+------------------------+-------+| lower_case_table_names | 0 |+------------------------+-------+1 row in set (0.00 sec)mysql> mysql> use mydb;Database changedmysql> create table test(id int);Query OK, 0 rows affected (0.07 sec)mysql> create table TEST(id int);Query OK, 0 rows affected (0.09 sec)mysql> insert into test values(1);Query OK, 1 row affected (0.03 sec)mysql> insert into TEST value(2);Query OK, 1 row affected (0.00 sec)mysql> select * from test;+------+| id |+------+| 1 |+------+1 row in set (0.00 sec)mysql> select * from TEST;+------+| id |+------+| 2 |+------+1 row in set (0.00 sec)mysql> |
|
新聞熱點(diǎn)
疑難解答
圖片精選