我要加这张表:

CREATE TABLE contenttype (
        contenttypeid INT UNSIGNED NOT NULL AUTO_INCREMENT,
        class VARBINARY(50) NOT NULL,
        packageid INT UNSIGNED NOT NULL,
        canplace ENUM('0','1') NOT NULL DEFAULT '0',
        cansearch ENUM('0','1') NOT NULL DEFAULT '0',
        cantag ENUM('0','1') DEFAULT '0',
        canattach ENUM('0','1') DEFAULT '0',
        isaggregator ENUM('0', '1') NOT NULL DEFAULT '0',
        PRIMARY KEY (contenttypeid),
        UNIQUE KEY packageclass (packageid, class)
);

我得到一个1050"表已经存在"

但表不存在。有什么想法吗?

编辑:更多细节,因为每个人似乎都不相信我:)

DESCRIBE contenttype

产量:

1146-表'gunzfact_vbforumdb.contenttype'不存在

CREATE TABLE gunzfact_vbforumdb.contenttype(
contenttypeid INT UNSIGNED NOT NULL AUTO_INCREMENT ,
class VARBINARY( 50 ) NOT NULL ,
packageid INT UNSIGNED NOT NULL ,
canplace ENUM( '0', '1' ) NOT NULL DEFAULT '0',
cansearch ENUM( '0', '1' ) NOT NULL DEFAULT '0',
cantag ENUM( '0', '1' ) DEFAULT '0',
canattach ENUM( '0', '1' ) DEFAULT '0',
isaggregator ENUM( '0', '1' ) NOT NULL DEFAULT '0',
PRIMARY KEY ( contenttypeid ) ,

产量:

1050-表'contenttype'已经存在

其他提示

从mysql日志:

InnoDB: You can drop the orphaned table inside InnoDB by
InnoDB: creating an InnoDB table with the same name in another
InnoDB: database and copying the .frm file to the current database.
InnoDB: Then MySQL thinks the table exists, and DROP TABLE will
InnoDB: succeed.
.

我得到了同样的错误,而修复表(从@ nulluserexception的答案)没有帮助。

我最终找到了这个解决方案

sudo mysqladmin flush-tables
.

对我来说,没有生成的icotagcode,我收到以下错误:

mysqladmin: refresh failed; error: 'Access denied; you need the RELOAD privilege for this operation'
.

(在OS x 10.6上运行)

您可能需要刷新表缓存。例如:

DROP TABLE IF EXISTS `tablename` ;
FLUSH TABLES `tablename` ; /* or exclude `tablename` to flush all tables */
CREATE TABLE `tablename` ...
.

我和这个吵了一整天:我有一个Perl脚本,通过首先做一个 DROP IF EXISTS ... 在他们身上,然后 CREATE在他们身上。该 DROP 成功了,但在 CREATE 我收到这个错误信息: table already exists

我终于弄清楚了:我正在使用的MySQL的新版本有InnoDB的默认引擎("show engine\G;")我在my中更改了它。cnf文件默认为MyISAM,重新启动MySQL,现在我不再得到"表已经存在"错误。

在创建视图时,我发生了同样的问题。 此视图是早些时候存在的,因为它被删除了一些更改,但是当我尝试再次添加它时,它就会向我显示“查看已经存在”错误消息。

解决方案

你可以手动做一件事。

  1. 转到安装它的mysql文件夹
  2. 转到它内部的数据文件夹。
  3. 选择您的数据库并进入它。
  4. 数据库创建“.frm”格式文件。
  5. 删除特定表的文件。
  6. 现在再次创建表。
  7. 它将成功创建表。

遇到同样的问题(创建Innodb表)这是最终为我工作的问题:

DROP DATABASE `having_issues`;
.

我检查了文件的基础,权限,试图修复和互化但没有工作。

因此,如果这是一个选项,将所有工作表移动到另一个数据库,删除旧的一个(您可能必须在下降前手动删除数据库文件夹中的任何文件),重命名新的,你“应该”回来。显然,无论使用InnoDB的“缓存”都会与原始数据库一起删除。

我在Win7中在SQL Maestro为MySQL 12.3遇到了这个问题。非常刺激,实际上是秀塞。没有帮助,甚至没有丢弃和重新创建数据库。我对XP有同样的设置,它在那里工作,所以在阅读你的答案后,我意识到它必须是Win7权限相关。所以我作为管理员ran mysql,即使SQL Maestro正常运行,也会消失。因此,它必须是Win7和MySQL之间的权限问题。

我也遇到这个问题在尝试创建一个表时表示它已经存在并丢弃表格说它不存在。

我做了“冲洗表”,它清除了问题。

我正在为同样的问题而挣扎。我无法创建表,即使它不存在。我尝试了上述所有解决方案,但没有成功。

我的解决方案是删除文件 ib_logfil0, ib_logfile1, ibdata1, ,而 auto.cnf 从MySQL的data文件夹;请确保在删除这些文件之前先停止MySQL服务。

然后在重新启动服务后,MySQL重新创建了这些文件,我能够运行备份脚本。 CREATEs被存储(一个sqldump文件)。

首先检查您是否在正确的数据库中 USE yourDB 并尝试 Select * from contenttype 只是为了看看它是什么,如果它真的存在。..

我在Mac OS X和MySQL 5.1.40处具有相同的问题。我使用Eclipse编辑我的SQL脚本,而不是我尝试了MySQLWorkBench 5.2.28。可能它将换行符转换为MAC格式。在我在文件中注释出第一行之前,我不知道我的脚本有什么问题。在此之后,此脚本被MySQL解释为一个单一注释。我使用build-in textedit mac应用程序来解决这个问题。在线中断后转换为正确的格式,错误1050消失了。

Eclipse用户更新:

要在整个工作空间中设置创建的新文件的默认结尾:

窗口 - >首选项 - >常规 - > 工作区 - >新文文件行 分隔符。

要转换现有文件,请打开要编辑的文件和当前编辑的文件,转到菜单:

文件 - >转换线分隔符到

我有这个同样的情况。问题最终是父目录的权限。

在测试期间,我一直在复制文件中和yeysql。

drwx------   3 _mysql  wheel 
.

是不够的,需要是:

-rw-rw----   3 _mysql  wheel 
.

抱歉复活。

我遇到了错误1050和150的巨大问题。

对我来说,问题是我试图添加一个约束 ON DELETE SET NULL 作为条件之一。

更改为 ON DELETE NO ACTION 允许我添加所需的FK约束。

不幸的是,MySql错误消息完全没有帮助,所以我不得不迭代地找到这个解决方案,并在上面问题的答案的帮助下。

I had this same problem and it looks like the Database name was case sensitive. My Database is called:

Mydatabase

Whilst my script included

USE mydatabase

Once I changed the database name to the correct case it all seemed to work. Using MYSQL Workbench on MAC OSX

This problem also occurs if a 'view' (imaginary table) exists in database as same name as our new table name.

In my case I found this to be an issue with InnoDB; I never discovered what the actual problem was, but creating as a MyISAM allowed it to build

For me the problem was caused when using a filesystem copy of the mysql database directory instead of mysqldump. I have some very large tables, mostly MyISAM and a few InnoDB cache tables and it is not practical to mysqldump the data. Since we are still running MyISAM, XtraBackup is not an option.

The same symptoms as above happened to me. The table is not there, there are no files in the directory that pertain to the table, yet it cannot be created because MySQL thinks its there. Drop table says it's not there, create table says it is.

The problem occurred on two machines, both were fixed by copying backups. However, I noticed that in my backup that there was a .MYD and .MYI file, even though I was under the impression that these files are not used for InnoDB. The .MYD and .MYI files had an owner of root, while the .frm was owned by mysql.

If you copy from backup, check the file permissions. Flush tables might work, but I opted to shut down and restart the database.

Good luck.

gosh, i had the same problem with osCommerce install script until i figured out the mysql system has many databases and the create table query copies itself into each one and thus droping only the working table on active db didnt help, i had to drop the table from all dbs

My CREATE statement was part of staging env dump.

I did try everything that has been mentioned above. I DID NOT get solution. However my path to redemption was:

  1. I stumble upon the fact that (one of many in) the CREATE statement did get through when I rectified the database name case sensitivity. This clicked something. I repeated the same for the other tables.

  2. However a new error came into the scene. The straight quotes for 'comments' were throwing syntax error. I was shocked. replaced them but the new error started popping up. Finally i knew the solution.

SOLUTION: The dump i was using might have been from a different version of MySql. I got permission to connect to the staging MYsql using the local(installed on my machine) mysql workbench. I did not rdp into the staging server to login to staging mysql workbench. Created a dump from there. Ran the dump and it worked like a sweet.

Was trying to import a backup sql file but was getting the error; 1050 "Table already exists"

My setup was:

  • Windows 7
  • Mysql 5.5.16

Solution:

  1. Changed the server engine from InnoDB to MyISAM
  2. Using phpMyAdmin Deleted the database I was trying to import to
  3. Restarted the mysql service
  4. Tried the re-importation and it worked

Your disk also might just be full. (just had that)

In my case the problem was that there was a view with the same name as my table, so I had to drop the view to allow the import to continue.

drop view `my-view-that-has-same-name-as-table`;

An automated solution that worked for me is to replace the normal drop table with this sed during the dump to also drop any views that might exist:

mysqldump my-db \
| sed -E 's/^DROP TABLE IF EXISTS(.+)$/\0 DROP VIEW IF EXISTS\1/g' \
| mysql my-other-db

Or if you would rather print to a file for backup

mysqldump my-db \
| sed -E 's/^DROP TABLE IF EXISTS(.+)$/\0 DROP VIEW IF EXISTS\1/g' \
> my-db.dump.sql

Or if you received the dumped file and you are importing it to your db

cat my-db.dump.sql \
| sed -E 's/^DROP TABLE IF EXISTS(.+)$/\0 DROP VIEW IF EXISTS\1/g' \
| mysql my-other-db

You get the idea

Note: it is important that you add the ^ at the beginning of the replacement regex, because there are other types of DROP TABLE IF EXISTS commands in dumps that you don't want to touch.

You go from having something like this:

--
-- Table structure for table `my_table`
--

DROP TABLE IF EXISTS `my_table`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `my_table` (
...

To having something like this:

--
-- Table structure for table `my_table`
--

DROP TABLE IF EXISTS `my_table`; DROP VIEW IF EXISTS `my_table`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `my_table` (
...

You won´t believe me! I´ve just removed a comment block from my .sql file and now it works.

CREATE DATABASE  IF NOT EXISTS `issga` /*!40100 DEFAULT CHARACTER SET utf8 */;
USE `issga`;
--
-- Table structure for table `protocolo`
--

DROP TABLE IF EXISTS protocolo;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
 CREATE TABLE protocolo (
  `idProtocolo` int(11) NOT NULL AUTO_INCREMENT,
  `tipo` varchar(30) DEFAULT NULL,
  `estado` int(2) DEFAULT 0,
  PRIMARY KEY (`idProtocolo`)
 ) ENGINE=InnoDB AUTO_INCREMENT=142 DEFAULT CHARSET=utf8;
 /*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `protocolo`
--

LOCK TABLES protocolo WRITE;
/*!40000 ALTER TABLE protocolo DISABLE KEYS */;
/* INSERT INTO `protocolo` VALUES () */
/*!40000 ALTER TABLE protocolo ENABLE KEYS */;
UNLOCK TABLES;

The deleted comment block was this:

--
-- Table structure for table `protocolo`
-- 

I´ve left the problematic table alone in the same .sql file. After that I´ve removed comments, the only code was left, and the error disappears.

I've just had the same error but I knew the table already existed and wanted to add to it. I'm adding my answer as this question comes up as no.1 for me on google when looking for the same error but for a slightly different scenario. Basically I needed to tick

"Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER statement"

And this solved the error for me.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top