简体   繁体   English

恢复sql转储文件时获取errno 150

[英]Get errno 150 when restoring sql dump file

I've use MySQL Dump Distrib 5.1.45 to backup my database. 我使用MySQL Dump Distrib 5.1.45来备份我的数据库。 It's generated a file a below: 它生成了一个文件如下:

-- MySQL dump 10.13  Distrib 5.1.45, for Win32 (ia32)
--
-- Host: localhost    Database: SG
-- ------------------------------------------------------
-- Server version   5.5.16

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

DROP TABLE IF EXISTS `hist`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `hist` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `HistUi` int(11) DEFAULT NULL,
  `StdModel` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`Id`),
  KEY `StdModel` (`StdModel`),
  CONSTRAINT `FKA0015AD86A02605F` FOREIGN KEY (`StdModel`) REFERENCES `std` (`Model`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

LOCK TABLES `hist` WRITE;
/*!40000 ALTER TABLE `hist` DISABLE KEYS */;
/*!40000 ALTER TABLE `hist` ENABLE KEYS */;
UNLOCK TABLES;

DROP TABLE IF EXISTS `std`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `std` (
  `Model` varchar(30) NOT NULL,
  `Owner` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`Model`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

But when I try to restore from that file, I fails and show a message such as: 但是当我尝试从该文件恢复时,我失败并显示如下消息:

ERROR 1005 (HY000): Can’t create table ‘SG.hist’ (errno: 150)

I try some solutions got from Google search but not work: 我尝试从谷歌搜索获得的一些解决方案,但没有工作:

  • Add SET FOREIGN_KEY_CHECKS = 0; 添加SET FOREIGN_KEY_CHECKS = 0; on top of dump file 在转储文件之上
  • Use mysql.exe from MySql Server 5.5 使用MySql Server 5.5中的mysql.exe
  • Use MySql Workbench 使用MySql Workbench
  • ... ...

I wasted too may time on this issue but still can't find the root cause leading to the problem. 我也浪费时间在这个问题上,但仍然找不到导致问题的根本原因。 I cannot use newer mysqldump.exe file to create dump file again, and don't want to change database structure now. 我不能再使用较新的mysqldump.exe文件来创建转储文件,现在也不想更改数据库结构。 A little change in sql dump file is acceptable. 可以接受sql dump文件中的一点变化。

Update: 更新:

Bring that file to other PCs which have the same MySQL server and it works fine. 将该文件带到具有相同MySQL服务器的其他PC,并且工作正常。 I tried to compare my.ini files, even copying my.ini file from another PC doesn't make it worked. 我试图比较my.ini文件,即使从另一台PC上复制my.ini文件也无法正常工作。

I had the same problem, which I believe was caused by tables that were expected to be created later in the same dump file already existing, perhaps with slightly different definitions. 我遇到了同样的问题,我认为这是由于预期稍后在已经存在的同一个转储文件中创建的表引起的,可能定义略有不同。 I dropped the database and recreated it from scratch and everything worked fine. 我删除了数据库并从头开始重新创建它,一切正常。 Could this be your problem? 这可能是你的问题吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM