MySQL 中的表名是否区分大小写?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6134006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:01:57  来源:igfitidea点击:

Are table names in MySQL case sensitive?

mysqlcase-sensitivemysql5

提问by benstpierre

Are table names in MySQL case sensitive?

MySQL 中的表名是否区分大小写?

On my Windows development machine the code I have is able to query my tables which appear to be all lowercase. When I deploy to the test server in our datacenter the table names appear to start with an uppercase letter.

在我的 Windows 开发机器上,我拥有的代码能够查询我的表,这些表似乎都是小写的。当我部署到我们数据中心的测试服务器时,表名似乎以大写字母开头。

The servers we use are all on Ubuntu.

我们使用的服务器都在 Ubuntu 上。

回答by CloudyMarble

In general:

一般来说:

Database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix.

数据库和表名在 Windows 中不区分大小写,而在大多数 Unix 版本中区分大小写。

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. Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database and table names.

在 MySQL 中,数据库对应于数据目录中的目录。数据库中的每个表对应于数据库目录中的至少一个文件。因此,底层操作系统的区分大小写在数据库和表名称的区分大小写中起作用。

One can configure how tables names are stored on the disk using the system variable lower_case_table_names(in the my.cnfconfiguration file under [mysqld]).

可以使用系统变量lower_case_table_names(在[mysqld] 下的my.cnf配置文件中)配置表名称如何存储在磁盘上。

Read the section: 10.2.2 Identifier Case Sensitivityfor more information.

阅读部分:10.2.2 标识符区分大小写以获取更多信息。

回答by StephenLembert

Database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix or Linux.

数据库和表名在 Windows 中不区分大小写,而在大多数 Unix 或 Linux 版本中区分大小写。

to resolve the issue set the lower_case_table_names to 1

要解决此问题,请将lower_case_table_names 设置为1

lower_case_table_names=1

lower_case_table_names=1

this will make all your tables lowercase, no matter how you write them

这将使您的所有表格小写,无论您如何编写它们

回答by Oswald

Table names in MySQL are file system entries, so they are case insensitive if the underlying file system is.

MySQL 中的表名是文件系统条目,因此如果底层文件系统是它们,则它们不区分大小写。

回答by Raman Sahasi

It depends upon lower_case_table_namessystem variable:

这取决于lower_case_table_names系统变量:

show variables where Variable_name='lower_case_table_names'

There are three possible values for this:

这有三个可能的值:

  • 0- lettercase specified in the CREATE TABLEor CREATE DATABASEstatement. Name comparisons are case sensitive.
  • 1- Table names are stored in lowercase on disk and name comparisons are not case sensitive.
  • 2- lettercase specified in the CREATE TABLEor CREATE DATABASEstatement, but MySQL converts them to lowercase on lookup. Name comparisons are not case sensitive.
  • 0- 在CREATE TABLEorCREATE DATABASE语句中指定的字母。名称比较区分大小写。
  • 1- 表名以小写形式存储在磁盘上,名称比较不区分大小写。
  • 2- 在CREATE TABLEorCREATE DATABASE语句中指定的字母,但 MySQL 在查找时将它们转换为小写。名称比较不区分大小写。

Documentation

文档

回答by sendon1982

  1. Locate file at /etc/mysql/my.cnf

  2. Edit the file by adding the following lines:

    [mysqld]

    lower_case_table_names=1

  3. sudo /etc/init.d/mysql restart

  4. run mysqladmin -u root -p variables | grep tableto check that lower_case_table_namesis 1now

  1. 找到文件在 /etc/mysql/my.cnf

  2. 通过添加以下行来编辑文件:

    [mysqld]

    lower_case_table_names=1

  3. sudo /etc/init.d/mysql restart

  4. 运行mysqladmin -u root -p variables | grep table检查lower_case_table_names1现在

You might need to re-create these tables to make it work

您可能需要重新创建这些表以使其工作