mysql - 如何将 Linux 服务器中的 MySQL 表名更改为不区分大小写?

标签 mysql linux case-insensitive

我正在开发一个曾经托管在 Apple 服务器上的旧网站。当它迁移到新的 Linux 服务器时,它停止工作。我很确定这是因为 php 脚本中使用的所有 MySQL 查询对表名都有不同的大小写组合(我不知道为什么原始开发人员在创建表名或 php 脚本时没有遵循任何约定) 这并不重要,因为 Mac 和 Windows MySQL 服务器默认情况下都不区分大小写。但是,Linux 不是。

有没有办法改变 MySQL 上的 Linux 默认值,使其变得不区分大小写并且像 Mac 或 Windows 一样工作?我一直在寻找,但没有找到任何不涉及更改脚本或表名或两者的答案。该网站必须是使用某些 CMS 生成的,因此有几十个页面,并在每个表和数百个表中包含具有多个查询的文件。我开始尝试以我能想到的最聪明的方式实现这种类型的解决方案,但是如果我触摸表名,那么其他当前工作的页面就会停止工作(我试图避免进一步破坏网站)。

我在 Linux 服务器的 Webmin 中的 MySQL 服务器控制台中有一个系统变量 (lower_case_table_names),我可以将其从 0 更改为 1 以解决此问题,但 Webmin 不允许我更改它,因为它是“只读”变量。

你会认为这是一个很容易解决的问题,但到目前为止我已经失去了希望。我希望有人能得到一个我现在可能无法理解的答案。

最佳答案

MySQL 的大小写敏感性默认由文件系统处理,这就是您发现此差异的原因:

9.2.2. 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). Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database and table names. This means database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix. One notable exception is Mac OS X, which is Unix-based but uses a default file system type (HFS+) that is not case sensitive. However, Mac OS X also supports UFS volumes, which are case sensitive just as on any Unix. See Section 1.8.4, “MySQL Extensions to Standard SQL”.

幸运的是,下一句话可以帮到你:

The lower_case_table_names system variable also affects how the server handles identifier case sensitivity, as described later in this section.

lower_case_table_names 简介:

If set to 0, table names are stored as specified and comparisons are case sensitive. If set to 1, table names are stored in lowercase on disk and comparisons are not case sensitive. If set to 2, table names are stored as given but compared in lowercase. This option also applies to database names and table aliases. For additional information, see Section 9.2.2, “Identifier Case Sensitivity”.

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 set this variable to 0 on such a system and access MyISAM tablenames using different lettercases, index corruption may result. On Windows the default value is 1. On Mac OS X, the default value is 2.

看来您应该在 MySQL 配置文件中将 lower_case_table_names 设置为 1

关于mysql - 如何将 Linux 服务器中的 MySQL 表名更改为不区分大小写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11165944/

相关文章:

Git 一次使用普通名称获取一个分支,一次使用大写字母

javascript - JavaScript 中不区分大小写的字符串替换?

git status 显示两个文件因大小写重命名后被修改

mysql - 与 mysql 的连接在本地工作正常,但不能作为 AWS lambda 函数

java - 第 1 行不包含所有列的数据 MySQL JDBC Eclipse 错误

php - MYSQL select查询多条件且if输入不为空

c - 在脚本中使用 sleep 会消耗 cpu 周期吗?

linux - gnuplot 中缩写日的问题

mysql - 触发器@DBMS 出现问题

具有顺序输出的 unix shell 脚本中的 HTML