Windows 中的 MySQL 小写表名 Unix 上的大写名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1172382/
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 13:43:22  来源:igfitidea点击:

MySQL Lowercase Table Names in Windows Uppercase names on Unix

mysql

提问by gus

I have a a problem whereby my production server runs Unix and my dev server runs MS Windows. The problem is that Windows is not case sensitive and Unix is. So my table set on the production server uses Uppercase table names ie "Customers" and on Windows the table names are in lowercase "customers".

我有一个问题,我的生产服务器运行 Unix,而我的开发服务器运行 MS Windows。问题是 Windows 不区分大小写,而 Unix 是。所以我在生产服务器上设置的表使用大写的表名,即“Customers”,而在 Windows 上,表名是小写的“customers”。

All this is fine until you need to get data from one box to another and your SQL export says insert into "customers" in lowercase, and presto "Unkown table customers". Because the production server is currently on a shared hosting plan i cant change the settings and install the key that ignores case.

所有这一切都很好,直到您需要将数据从一个盒子获取到另一个盒子,并且您的 SQL 导出显示以小写形式插入“customers”,并快速插入“Unkown table customers”。因为生产服务器当前处于共享托管计划中,所以我无法更改设置并安装忽略大小写的密钥。

So my question, is there a way to get Windows to convert the tables back to the correct case or is there some setting I can include in the export SQL file so that i can upload data without this problem.

所以我的问题是,有没有办法让 Windows 将表转换回正确的大小写,或者是否有一些设置可以包含在导出 SQL 文件中,以便我可以上传数据而不会出现此问题。

Thanks

谢谢

UPDATE

更新

Here is what I discovered for anybody else having this issue.

这是我为其他遇到此问题的人发现的内容。

If you have already set up your tables running MySQL on Windows adding lower_case_table_names=2 to your my.cnf or my.ini file will not change the case of your tables automatically even if they were originally created using uppercase or mixed case names.

如果您已经在 Windows 上设置了运行 MySQL 的表,向 my.cnf 或 my.ini 文件添加 lower_case_table_names=2 不会自动更改表的大小写,即使它们最初是使用大写或混合大小写名称创建的。

CREATE TABLE"MyTable" will create a new table "mytable" not"MyTable" even when lower_case_table_names=2 is set in your my.cnf file.

CREATE TABLE"MyTable" 将创建一个新表 "mytable"而不是"MyTable",即使在 my.cnf 文件中设置了lower_case_table_names=2。

To get around this problem use this method

要解决此问题,请使用此方法

  1. Make a copy of your original table
  2. Drop your original table
  3. Renameyour copy table using the correct case.
  1. 制作原始表格的副本
  2. 放下你原来的桌子
  3. 使用正确的大小写重命名您的副本表。

This is the only way it will work. Hope this helps somebody.

这是它将起作用的唯一方法。希望这可以帮助某人。

回答by codemonkey

Taken from dev.mysql.com:

摘自dev.mysql.com

To avoid data transfer problems arising from lettercase of database or table names, you have two options:

为避免因数据库或表名的字母大小写引起的数据传输问题,您有两种选择:

  • Use lower_case_table_names=1 on all systems. The main disadvantage with this is that when you use SHOW TABLES or SHOW DATABASES, you do not see the names in their original lettercase.
  • Use lower_case_table_names=0 on Unix and lower_case_table_names=2 on Windows. This preserves the lettercase of database and table names. The disadvantage of this is that you must ensure that your statements always refer to your database and table names with the correct lettercase on Windows. If you transfer your statements to Unix, where lettercase is significant, they do not work if the lettercase is incorrect.
  • 在所有系统上使用lower_case_table_names=1。这样做的主要缺点是,当您使用 SHOW TABLES 或 SHOW DATABASES 时,您看不到原始字母中的名称。
  • 在 Unix 上使用lower_case_table_names=0,在Windows 上使用lower_case_table_names=2。这保留了数据库和表名的字母大小写。这样做的缺点是您必须确保您的语句在 Windows 上始终使用正确的字母来引用您的数据库和表名称。如果你把你的语句转移到 Unix 上,在这种情况下,字母是重要的,如果字母不正确,它们将不起作用。

Exception: If you are using InnoDB tables and you are trying to avoid these data transfer problems, you should set lower_case_table_names to 1 on all platforms to force names to be converted to lowercase.

例外:如果您正在使用 InnoDB 表并试图避免这些数据传输问题,您应该在所有平台上将 lower_case_table_names 设置为 1 以强制名称转换为小写。

If you plan to set the lower_case_table_names system variable to 1 on Unix, you must first convert your old database and table names to lowercase before stopping mysqld and restarting it with the new variable setting.

如果您打算在 Unix 上将 lower_case_table_names 系统变量设置为 1,则必须先将旧的数据库和表名转换为小写,然后再停止 mysqld 并使用新的变量设置重新启动它。

回答by Wolfgang Blessen

There is one easy solution:

有一个简单的解决方案:

Always name your tablenames lowercase.

始终将您的表名命名为小写。

回答by chaos

The universal guiding philosophy of Windows with respect to case is "case-insensitive, case stored". That means Windows never intends to discardyour case, so it's a little mysterious why your tables on Windows arelower-case.

Windows 关于大小写的普遍指导理念是“不区分大小写,大小写存储”。这意味着 Windows 从不打算丢弃您的大小写,因此为什么您在 Windows的表小写的有点神秘。

Apologies if this is a dumb question, but have you tried renaming the tables on the Windows machine so they have the correct case pattern?

抱歉,如果这是一个愚蠢的问题,但是您是否尝试过重命名 Windows 机器上的表,以便它们具有正确的大小写模式?