Windows上的MySQL小写表名称Unix上的大写名称 [英] MySQL Lowercase Table Names in Windows Uppercase names on Unix

查看:95
本文介绍了Windows上的MySQL小写表名称Unix上的大写名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,我的生产服务器运行Unix,而我的开发服务器运行MS Windows. 问题是Windows不区分大小写,而Unix区分大小写.因此,我在生产服务器上设置的表使用大写的表名,即"Customers",而在Windows上,表名使用小写的"customers".

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

这一切都很好,除非您需要将数据从一个盒子中获取到另一个盒子,并且您的SQL导出说要以小写形式插入客户",然后保存未知表客户".由于生产服务器当前处于共享主机计划中,因此我无法更改设置并安装忽略大小写的密钥.

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.

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

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.

谢谢

更新

这是我为遇到此问题的其他人所发现的.

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

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

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.

创建表即使在my.cnf文件中设置了lower_case_table_names = 2,"MyTable"也将创建一个新表"mytable".

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.

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

To get around this problem use this method

  1. 复制原始表格
  2. 删除原始表格
  3. 使用正确的大小写
  4. 重命名您的副本表.
  1. Make a copy of your original table
  2. Drop your original table
  3. Rename your copy table using the correct case.

这是它将起作用的唯一方法.希望这对某人有帮助.

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

推荐答案

来自 dev.mysql.com :

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

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

  • 在所有系统上使用lower_case_table_names = 1.这样做的主要缺点是,当您使用SHOW TABLES或SHOW DATABASES时,看不到其名称的原始字母大写.
  • 在Unix上使用lower_case_table_names = 0,在Windows上使用lower_case_table_names = 2.这将保留数据库和表名的字母大小写.这样做的缺点是,必须确保您的语句在Windows上始终以正确的字母大小写引用数据库和表名.如果将语句转移到大写字母大写的Unix,则如果大写字母不正确,则它们将不起作用.

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

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.

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

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.

这篇关于Windows上的MySQL小写表名称Unix上的大写名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆