2012-01-27 157 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

我建議你重新啓動你的數據庫服務器。我以前遇到過類似的問題。

相關問題