Mysql 1050 错误“表已存在”事实上,它并没有

发布于 2024-09-11 00:24:43 字数 1242 浏览 14 评论 0原文

我正在添加此表:

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”已存在

I'm adding this table:

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)
);

And I get a 1050 "table already exists", but the table does NOT exist.

DESCRIBE contenttype

yields:

1146 - Table 'gunzfact_vbforumdb.contenttype' doesn't exist

and

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 ) ,

Yields:

1050 - Table 'contenttype' already exists

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(28

抹茶夏天i‖ 2024-09-18 00:24:44

我也遇到了这个问题,尝试创建表时说它已经存在,而删除表时说它不存在。

我做了“FLUSH TABLES”,它解决了问题。

I also encountered this problem where trying to Create a table said it already exists and Dropping the table said it didn't exist.

I did "FLUSH TABLES" and it cleared the problem.

心凉怎暖 2024-09-18 00:24:44

首先检查您是否位于正确的数据库中 USE yourDB 并尝试 Select * from contenttype 只是为了看看它是什么以及它是否确实存在......

First check if you are in the right database USE yourDB and try Select * from contenttype just to see what is it and if it exists really...

绮烟 2024-09-18 00:24:44

我在 Mac OS X 和 MySQL 5.1.40 上遇到了同样的问题。我使用 eclipse 来编辑 SQL 脚本,然后尝试了 MySQLWorkbench 5.2.28。可能它将换行符转换为 Mac 格式。在我注释掉文件中的第一行之前,我不知道我的脚本出了什么问题。此后,该脚本被 mysql 解释为一条注释。我使用内置的 TextEdit Mac 应用程序来解决这个问题。将换行符转换为正确的格式后,错误 1050 消失了。

针对 Eclipse 用户的更新:

要为整个工作区中创建的新文件设置默认结尾:

窗口 ->首选项->一般->
工作区 ->新文本文件行
分隔符。

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

文件->将行分隔符转换为

I had the same problem at Mac OS X and MySQL 5.1.40. I used eclipse to edit my SQL script and than I tried MySQLWorkbench 5.2.28. Probably it converted newline characters to Mac format. I had no idea about what's wrong with my script until I commented out the first line in file. After this this script was interpreted by mysql as a one single comment. I used build-in TextEdit Mac application to fix this. After line-breaks was converted to the correct format, the error 1050 gone.

Update for Eclipse users:

To set up default ending for new files created, across the entire workspace:

Window -> Preferences -> General ->
Workspace -> New text file line
delimiter.

To convert existing files, open file for editing and for the currently edited file, go to the menu:

File -> Convert Line Delimiters To

挽清梦 2024-09-18 00:24:44

我也有同样的情况。问题最终出在父目录的权限上。

我在测试期间一直在 mysql 中复制文件。

drwx------   3 _mysql  wheel 

还不够,还需要:

-rw-rw----   3 _mysql  wheel 

抱歉复活。

I had this same case. The problem ended up being permissions on the parent directory.

I had been copying files in and out of mysql during testing.

drwx------   3 _mysql  wheel 

was not enough, needed to be:

-rw-rw----   3 _mysql  wheel 

Sorry to resurrect.

甜心 2024-09-18 00:24:44

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

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

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

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

I was having huge issues with Error 1050 and 150.

The problem, for me was that I was trying to add a constraint with ON DELETE SET NULL as one of the conditions.

Changing to ON DELETE NO ACTION allowed me to add the required FK constraints.

Unfortunately the MySql error messages are utterly unhelpful so I had to find this solution iteratively and with the help of the answers to the question above.

撧情箌佬 2024-09-18 00:24:44

您的磁盘也可能已满。 (刚刚有那个)

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

み零 2024-09-18 00:24:44

我遇到了同样的问题,看起来数据库名称区分大小写。我的数据库被称为:

Mydatabase

虽然我的脚本包含在内,但

USE mydatabase

一旦我将数据库名称更改为正确的大小写,一切似乎都有效。在 MAC OSX 上使用 MYSQL Workbench

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

心的位置 2024-09-18 00:24:44

如果数据库中存在与我们的新表名同名的“视图”(假想表),也会出现此问题。

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

旧竹 2024-09-18 00:24:44

就我而言,我发现这是 InnoDB 的问题;我从未发现实际问题是什么,但创建为 MyISAM 允许它构建

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

单身情人 2024-09-18 00:24:44

对我来说,问题是在使用 mysql 数据库目录的文件系统副本而不是 mysqldump 时引起的。我有一些非常大的表,主要是 MyISAM 和一些 InnoDB 缓存表,并且 mysqldump 数据不切实际。由于我们仍在运行 MyISAM,因此 XtraBackup 不是一个选项。

我也出现了和上面一样的症状。该表不存在,目录中没有与该表相关的文件,但无法创建它,因为 MySQL 认为它存在。删除表说它不存在,创建表说它存在。

该问题发生在两台机器上,均通过复制备份修复。然而,我注意到在我的备份中有一个 .MYD 和 .MYI 文件,尽管我的印象是这些文件不用于 InnoDB。 .MYD 和 .MYI 文件的所有者为 root,而 .frm 文件的所有者为 mysql。

如果从备份复制,请检查文件权限。刷新表可能有效,但我选择关闭并重新启动数据库。

祝你好运。

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.

無心 2024-09-18 00:24:44

天哪,我在 osCommerce 安装脚本中遇到了同样的问题,直到我发现 mysql 系统有许多数据库,而 create table 查询将自身复制到每个数据库中,从而只删除活动数据库上的工作表没有帮助,我不得不从所有数据库中删除该表

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

夜光 2024-09-18 00:24:44

我的 CREATE 语句是暂存环境转储的一部分。

我确实尝试了上面提到的一切。我没有得到解决方案。然而我的救赎之路是:

  1. 我偶然发现一个事实,当我纠正数据库名称大小写敏感性时,CREATE 语句(其中的许多语句之一)确实通过了。这点击了一些东西。我对其他表重复了相同的操作。

  2. 然而,出现了新的错误。 “评论”的直引号引发语法错误。我很震惊。替换了它们,但新的错误开始出现。最后我知道了解决方案。

解决方案:我使用的转储可能来自不同版本的 MySql。我获得了使用本地(安装在我的计算机上)mysql 工作台连接到临时 MYsql 的权限。我没有通过 rdp 进入登台服务器来登录登台 mysql 工作台。从那里创建了一个转储。运行转储,它的效果就像一个糖果。

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.

不疑不惑不回忆 2024-09-18 00:24:44

尝试导入备份 sql 文件但出现错误; 1050“表已存在”

我的设置是:

  • Windows 7
  • Mysql 5.5.16

解决方案:

  1. 使用 phpMyAdmin将服务器引擎从 InnoDB 更改为 MyISAM
  2. 删除了我试图导入的数据库
  3. 重新启动 mysql 服务
  4. 尝试重新导入,它起作用了

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
我不在是我 2024-09-18 00:24:44

就我而言,问题是有一个与我的表同名的视图,因此我必须删除该视图以允许继续导入。

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

对我有用的自动化解决方案是在转储期间用此 sed 替换正常的删除表,以同时删除可能存在的任何视图:

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

或者如果您宁愿打印到文件进行备份

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

或者如果您收到转储的文件并且您是将其导入到数据库中

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

您明白了

注意:在替换正则表达式的开头添加 ^ 非常重要,因为还有其他类型的 DROP TABLE IF EXISTS 转储中您不想触及的命令。

你从拥有这样的东西:

--
-- 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` (
...

到拥有这样的东西:

--
-- 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` (
...

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` (
...
指尖微凉心微凉 2024-09-18 00:24:44

我刚刚遇到了同样的错误,但我知道该表已经存在并想添加到其中。我添加了我的答案,因为当我在谷歌上寻找相同的错误但略有不同的场景时,这个问题对我来说是第一个问题。基本上我需要勾选

“添加DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT / TRIGGER statements”,

这解决了我的错误。

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.

心房敞 2024-09-18 00:24:44

我在新的空数据库上导入 Magento 电子商务的 .sql 转储时遇到同样的错误。我已经尝试了上面的一些解决方案,但没有任何效果,我已经通过更改转储的创建方式解决了问题。

创建转储时添加单个事务修复问题。

I had the same error importing a .sql dump for a Magento eCommerce on a new empty database. I've tried some of the solutions above but none worked, I've fixed the problem changing the way the dump was created.

Adding single transaction when creating the dump fixed the problem.

治碍 2024-09-18 00:24:44

您必须删除 mysql/data/yourdatabase 中数据库文件夹内的文件,因为即使您已删除/删除 phpmyadmin 中的表,该文件夹的文件也不会删除。图片供删除内容参考

You must delete the files inside the folder of your database in mysql/data/yourdatabase because even though you've deleted/drop table in phpmyadmin the folder's files did not delete.picture is for reference of what to delete

自演自醉 2024-09-18 00:24:44

需要混合所有内容来解决我的问题,按以下顺序:

注意:此解决方案将删除损坏的表的数据

  1. 创建临时数据库(db_temp);
  2. db_temp 中创建一个具有相同名称和架构的表 (twin_table)
  3. 移至 db_temp 表的文件夹 -> cd /var/lib/mysql/db_temp/
  4. 将所需的表.frm复制到product_db -> cp twin_table.frm ../Production_db/
  5. 更改Production_db中.ibd和.frm文件的权限-> chmod a+rw twin_table.frmchmod a+rw twin_table.ibd
  6. 访问mysql终端 -> mysql -u root -p
  7. 使用生产数据库 -> USE Production_db;
  8. 刷新表 -> FLUSH TABLES;
  9. 删除损坏的表 -> DROP TABLE twin_table;
  10. 重新创建表 -> 创建表 twin_table(表配置位于此处);

Needed to a mixed of everything to solve my problem, in this order:

Atention: this solution will erase your broken table's data

  1. Create temporary db (db_temp);
  2. Create a table with SAME NAME and schema in db_temp (twin_table)
  3. Move to db_temp table's folder -> cd /var/lib/mysql/db_temp/
  4. Copy desired table .frm to production_db -> cp twin_table.frm ../production_db/
  5. Change permissions of .ibd and .frm files in production_db-> chmod a+rw twin_table.frm and chmod a+rw twin_table.ibd
  6. Access mysql terminal -> mysql -u root -p
  7. Use production_db -> USE production_db;
  8. Flush tables -> FLUSH TABLES;
  9. Drop broken table -> DROP TABLE twin_table;
  10. re-create table -> CREATE TABLE twin_table (table config goes here);
看春风乍起 2024-09-18 00:24:43

听起来你有薛定谔表...

现在说真的,你可能有一张破桌子。尝试:

  • DROP TABLE IF EXISTS contenttype
  • REPAIR TABLE contenttype
  • 如果您有足够的权限,请删除数据文件(在 /mysql/data/db_name 中)

Sounds like you have Schroedinger's table...

Seriously now, you probably have a broken table. Try:

  • DROP TABLE IF EXISTS contenttype
  • REPAIR TABLE contenttype
  • If you have sufficient permissions, delete the data files (in /mysql/data/db_name)
流星番茄 2024-09-18 00:24:43

来自 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.

from MySQL Log:

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.
狼性发作 2024-09-18 00:24:43

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

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

You may need to flush the table cache. For example:

DROP TABLE IF EXISTS `tablename` ;
FLUSH TABLES `tablename` ; /* or exclude `tablename` to flush all tables */
CREATE TABLE `tablename` ...
爱你是孤单的心事 2024-09-18 00:24:43

我遇到了同样的错误,并且 REPAIR TABLE (来自 @NullUserException 的答案)没有帮助。

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

sudo mysqladmin flush-tables

对我来说,没有sudo,我收到以下错误:(

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

在 OS X 10.6 上运行)

I got this same error, and REPAIR TABLE (from @NullUserException's answer) didn't help.

I eventually found this solution:

sudo mysqladmin flush-tables

For me, without the sudo, I got the following error:

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

(Running on OS X 10.6)

梦里人 2024-09-18 00:24:43

创建视图时我也遇到了同样的问题。
该视图较早出现,由于一些更改,它被删除了,但是当我尝试再次添加它时,它向我显示“视图已存在”错误消息。

解决方案

您可以手动执行一件事。

  1. 转到安装它的 MySQL 文件夹
  2. 转到其中的数据文件夹。
  3. 选择您的数据库并进入其中。
  4. 数据库创建“.frm”格式文件。
  5. 删除特定表的文件。
  6. 现在再次创建该表。

它将成功创建表。

Same problem occurred with me while creating a view.
The view was present earlier then due to some changes it got removed But when I tried to add it again it was showing me "view already exists" error message.

Solution:

You can do one thing manually.

  1. Go to the MySQL folder where you have installed it
  2. Go to the data folder inside it.
  3. Choose your database and go inside it.
  4. Data base creates ".frm" format files.
  5. delete the particular table's file.
  6. Now create the table again.

It will create the table successfully.

三生殊途 2024-09-18 00:24:43

我在 Win7 上的 Sql Maestro for MySql 12.3 中遇到了这个问题。非常令人恼火,事实上是一个表演障碍。没有任何帮助,甚至删除并重新创建数据库也没有帮助。我在 XP 上有相同的设置并且它在那里工作,所以在阅读了您关于权限的答案后,我意识到它一定与 Win7 权限相关。所以我以管理员身份运行MySql,即使Sql Maestro正常运行,错误也消失了。所以肯定是Win7和MySql之间的权限问题。

I had this problem on Win7 in Sql Maestro for MySql 12.3. Enormously irritating, a show stopper in fact. Nothing helped, not even dropping and recreating the database. I have this same setup on XP and it works there, so after reading your answers about permissions I realized that it must be Win7 permissions related. So I ran MySql as administrator and even though Sql Maestro was run normally, the error disappeared. So it must have been a permissions issue between Win7 and MySql.

巡山小妖精 2024-09-18 00:24:43

我一整天都在为此奋斗:我有一个 Perl 脚本,它通过首先对它们执行 DROP IF EXISTS ... 然后 CREATE 来构建一组表荷兰国际集团他们。 DROP 成功,但在 CREATE 上,我收到此错误消息:表已存在

我终于了解了它的底部:The new version of我正在使用的MySQL有一个默认引擎InnoDB(“显示引擎\ G;”)我在my.cnf文件中将其更改为默认为MyISAM,重新启动MySQL,现在我不再得到“表已经存在”错误。

I've been fighting with this all day: I have a Perl script that builds a set of tables by first doing a DROP IF EXISTS ... on them and then CREATEing them. The DROP succeeded, but on CREATE I got this error message: table already exists

I finally got to the bottom of it: The new version of MySQL that I'm using has a default engine of InnoDB ("show engine \G;") I changed it in the my.cnf file to default to MyISAM, re-started MySQL, and now I no longer get the "table already exists" error.

一梦等七年七年为一梦 2024-09-18 00:24:43

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

我的解决方案是从 data 文件夹中删除文件 ib_logfil0ib_logfile1ibdata1auto.cnf MySQL;确保在删除这些文件之前先停止 MySQL 服务。

然后重新启动服务后,MySQL 重新创建了这些文件,并且我能够运行备份脚本来存储我的所有 CREATE(一个 sqldump 文件)。

I am struggling with the same issue. I cannot create a table, even though it does not exist. I tried all the above solutions with no success.

My solution was to delete the files ib_logfil0, ib_logfile1, ibdata1, and auto.cnf from the data folder of MySQL; make sure to stop the MySQL service first before deleting these files.

Then after restarting the service, MySQL recreated these files and I was able to run a backup script were all my CREATEs were stored (a sqldump file).

凌乱心跳 2024-09-18 00:24:43

遇到同样的问题(创建 InnoDB 表),这最终对我有用:

DROP DATABASE `having_issues`;

我检查了文件基础、权限,尝试修复和刷新,但没有任何效果。

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

Encountering the same problem (create InnoDB table) this is what finally worked for me:

DROP DATABASE `having_issues`;

I checked on a file basis, permissions, tried to REPAIR and FLUSH but nothing worked.

So if this is an option, move all working tables to another DATABASE, drop the old one (you might have to manually remove any files from the database folder before the drop to work), rename the new one, and you 'should' be back on your way. Apparently, whatever gets 'cached' using InnoDB is dropped along with the original database.

梦巷 2024-09-18 00:24:43

你不会相信我的!我刚刚从 .sql 文件中删除了注释块,现在它可以工作了。

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;

删除的注释块是这样的:

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

我将有问题的表单独留在同一个 .sql 文件中。之后我删除了注释,只剩下唯一的代码,错误就消失了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文