We previously had a database in MySQL. In it, we had a table called trace. We’ve long since dropped the entire database and created another one with the same name. Now, we try to re-create the table trace from a backup script and we get table already exists. Even though there are clearly no tables in the new database. If I try to create a table that existed before, I get that error. If I create a random table that never existed then it’s fine.
Here is the code I am using to create the table:
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;
Error:
Table 'trace' already exists
We did have about 20 tables (trace was one of many) and there were lots of foreign keys if that helps. But we clearly dropped the DB and recreated it.
UPDATE
For testing, I tried this and it WORKS
CREATE TABLE trace (id INT,data VARCHAR(100));
However, after dropping that table and trying it again like this:
CREATE TABLE Trace (id INT,data VARCHAR(100));
It doesn’t work and I get the trace already exists error.
The difference is upper vs lowercase??
UPDATE 2
It is definitely an uppercase vs lowercase issue. Changing the table name from Trace to trace works even using the old script.
Any ideas on why this is so?
You might have wrong
lower_case_table_namessetting set on your MySQL Server. Correct values can be found In MySQL documentation. It states:If you’re using MySQL on Windows and have
lower_case_table_names=0then you might get this error because tableTrace(case-sensitive) does not exist in MySQL but fileTrace.frmalready exists on file system.