2012-01-27 153 views
0

我们以前在MySQL中有一个数据库。其中,我们有一张名为trace的表格。我们早已放弃了整个数据库并创建了另一个具有相同名称的数据库。现在,我们尝试从备份脚本重新创建表trace,我们得到table already exists。即使新数据库中显然没有表格。如果我尝试创建一个之前存在的表,我会得到该错误。如果我创建一个从不存在的随机表,那就没问题。为什么我不能在MySQL中创建表?

这里是我用来创建表的代码:

DROP TABLE IF EXISTS `Trace`; 
CREATE TABLE `Trace` (
    `TraceKey` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Trace Key', 
    `TableName` varchar(100) NOT NULL DEFAULT '' COMMENT 'Table Name', 
    `RecordKey` int(10) NOT NULL, 
    `Action` varchar(100) NOT NULL DEFAULT '', 
    `ActionTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Time Stamp', 
    `UserName` varchar(100) NOT NULL DEFAULT '' COMMENT 'UserName', 
    PRIMARY KEY (`TraceKey`) 
) ENGINE=InnoDB AUTO_INCREMENT=6735 DEFAULT CHARSET=latin1; 

错误:

Table 'trace' already exists 

我们的确有大约20桌(跟踪是许多之一),并有大量的外键如果有帮助。但是我们显然放弃了数据库并重新创建了它。

UPDATE

为了测试,我想这和它的作品

CREATE TABLE trace (id INT,data VARCHAR(100)); 

然而,再次下探该表,并试图像这样经过:

CREATE TABLE Trace (id INT,data VARCHAR(100)); 

一点也没有” t工作,我得到了trace already exists错误。

区别在于大写与小写?

更新2

这绝对是一个大写小写VS问题。即使使用旧脚本,将表名从Trace更改为trace也能正常工作。

关于这是为什么的任何想法?

+0

“SHOW TABLES”显示什么?它的输出中是否存在表“trace”? – 2012-01-27 14:38:29

+0

'SHOW TABLES'出现空白。 – cbmeeks 2012-01-27 14:39:26

+1

这与编程无关,也就是说你的sql是正确的,而不是问题,我会建议在服务器故障或数据库管理员询问这个问题 – 2012-01-27 14:49:10

回答

1

您可能在您的MySQL服务器上设置了错误的lower_case_table_names设置。正确的值可以找到In MySQL documentation。它指出:

If you are using MySQL on only one platform, you do not normally have to change the lower_case_table_names variable from its default value. However, you may encounter difficulties if you want to transfer tables between platforms that differ in file system case sensitivity. For example, on Unix, you can have two different tables named my_table and MY_TABLE, but on Windows these two names are considered identical. To avoid data transfer problems arising from lettercase of database or table names, you have two options:

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

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

    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.

如果你在Windows上使用MySQL和有lower_case_table_names=0然后,因为表Trace(区分大小写)并不在MySQL存在,但文件Trace.frm已经存在的文件系统上你可能会得到这个错误。

+0

我相信这对我最有帮助。我手动将我们的脚本更改为使用小写表名称,并且一切正常。我将研究如上所述设置正确的配置。谢谢 – cbmeeks 2012-01-27 14:52:49

0

我建议你重新启动你的数据库服务器。我以前遇到过类似的问题。

相关问题