在MySQL Dump文件中的Lesscased所有文本之后无法创建表

时间:2013-07-16 14:57:14

标签: mysql mysqldump database-restore

在降低mysql转储文件的内容后,我正在修复具有外键的表时出错。 我的目标是小写mysql数据库中的所有结构。 我尝试恢复数据库时使用vim来小写mysqldump文件的所有内容,这是我得到的错误。

$  mysql -u [user] -p[password] dme < mysqldump.sql
    ERROR 1005 (HY000) at line 399: Can't create table 'dme.contacts' (errno: 121)

在具有外键约束的任何表上恢复都是错误的。如果我删除每个表的主键后面的行,整个还原工作正常。

我的问题是,导致这种情况的原因是什么?我如何保留外键?

  1. Lowercased.sql示例导致错误(在dme.contacts之前有fyi,有多个表创建得很好。只有具有外键和Contstraints的表有问题。)

    drop table if exists `contacts`;
    /*!40101 set @saved_cs_client     = @@character_set_client */;
    /*!40101 set character_set_client = utf8 */;
    create table `contacts` (
      `contactid` int(11) not null auto_increment,
      `firstname` varchar(100) default null,
      `lastname` varchar(100) not null,
      `fullname` varchar(200) not null,
      `dob` datetime default null,
      `sex` char(1) default null,
      `voided` datetime default null,
      `vendorid` int(11) not null,
      `contacttypeid` int(11) default null,
      `comments` varchar(1500) default null,
      primary key (`contactid`),
      key `fk_contacts_vendors` (`vendorid`),
      key `fk_contacts_contacttype` (`contacttypeid`),
      constraint `fk_contacts_contacttype` foreign key (`contacttypeid`) references                 `contacttype` (`contacttypeid`) on delete no action on update no action,
      constraint `fk_contacts_vendors` foreign key (`vendorid`) references `vendors`         (`vendorid`) on delete no action on update no action
    ) engine=innodb default charset=utf8;
    /*!40101 set character_set_client = @saved_cs_client */;
    
    --
    -- dumping data for table `contacts`
    --
    
    lock tables `contacts` write;
    /*!40000 alter table `contacts` disable keys */;
    /*!40000 alter table `contacts` enable keys */;
    unlock tables;
    
  2. 原始来自mysqldump.sql(无错误)

    --
    -- Table structure for table `Contacts`
    --
    
    DROP TABLE IF EXISTS `Contacts`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `Contacts` (
      `ContactId` int(11) NOT NULL AUTO_INCREMENT,
      `FirstName` varchar(100) DEFAULT NULL,
      `LastName` varchar(100) NOT NULL,
      `FullName` varchar(200) NOT NULL,
      `DOB` datetime DEFAULT NULL,
      `Sex` char(1) DEFAULT NULL,
      `Voided` datetime DEFAULT NULL,
      `VendorID` int(11) NOT NULL,
      `ContactTypeID` int(11) DEFAULT NULL,
      `Comments` varchar(1500) DEFAULT NULL,
      PRIMARY KEY (`ContactId`),
      KEY `FK_Contacts_Vendors` (`VendorID`),
      KEY `FK_Contacts_ContactType` (`ContactTypeID`),
      CONSTRAINT `FK_Contacts_ContactType` FOREIGN KEY (`ContactTypeID`) REFERENCES `ContactType` (`ContactTYpeID`) ON DELETE NO ACTION ON UPDATE NO ACTION,
      CONSTRAINT `FK_Contacts_Vendors` FOREIGN KEY (`VendorID`) REFERENCES `Vendors` (`VendorId`) ON DELETE NO ACTION ON UPDATE NO ACTION
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `Contacts`
    --
    
    LOCK TABLES `Contacts` WRITE;
    /*!40000 ALTER TABLE `Contacts` DISABLE KEYS */;
    /*!40000 ALTER TABLE `Contacts` ENABLE KEYS */;
    UNLOCK TABLES;
    

1 个答案:

答案 0 :(得分:1)

尝试删除约束名称。样品:

constraint `fk_contacts_contacttype` foreign key (`contacttypeid`) ....

constraint foreign key (`contacttypeid`) ...