【问题标题】:Mysql ERROR 1064 (42000), database dump only created half the tablesMysql ERROR 1064 (42000),数据库转储只创建了一半的表
【发布时间】:2018-03-16 16:47:43
【问题描述】:

我正在尝试将现有数据库转储到我的实时服务器上,并且收到此错误消息。

到目前为止我做了什么:

  • 用 django 创建了我的网站并将迁移应用到 mysql
  • 在 mysql workbench 上打开数据库,检查所有表都在那里并且工作正常。 (当我在测试服务器上运行网站时,一切正常,所以我知道那里没有问题)
  • 将本地Mysql数据库导出为单个文件,通过FTP上传到服务器
  • 通过putty登录我的服务器,打开Mysql并进入相应的数据库,然后运行以下代码:

    source /home/ec2-user/fta_sport_database_4.sql
    
  • 这成功创建了 20 个所需数据库中的 14 个,但随后出现此错误:

    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
    
    '(6) NOT NULL,
      `post_category_id` int(11) NOT NULL,
      `team_a_id` int(11) DEFAU' at line 10
    

我打开了 SQL 文本文件,这是它似乎正在努力解决的代码:

CREATE TABLE `articles_post` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(100) NOT NULL,
  `post_slug` varchar(100) NOT NULL,
  `short_description` varchar(150) DEFAULT NULL,
  `body` longtext NOT NULL,
  `headline_image` varchar(100) DEFAULT NULL,
  `post_image` varchar(100) DEFAULT NULL,
  `youtube_link` varchar(200) DEFAULT NULL,
  `posted` datetime(6) NOT NULL,
  `post_category_id` int(11) NOT NULL,
  `team_a_id` int(11) DEFAULT NULL,
  `team_b_id` int(11) DEFAULT NULL,
  `headline_image_credit` varchar(150) DEFAULT NULL,
  `post_image_credit` varchar(150) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `post_slug` (`post_slug`),
  KEY `articles_post_posted_2a82c6bc` (`posted`),
  KEY `articles_post_team_a_id_ef2d8ab7_fk_teams_team_id` (`team_a_id`),
  KEY `articles_post_team_b_id_10d6b1e5_fk_teams_team_id` (`team_b_id`),
  KEY `articles_post_post_category_id_54408756_fk_sports_sport_id` (`post_category_id`),
  CONSTRAINT `articles_post_post_category_id_54408756_fk_sports_sport_id` FOREIGN KEY (`post_category_id`) REFERENCES `sports_sport` (`id`),
  CONSTRAINT `articles_post_team_a_id_ef2d8ab7_fk_teams_team_id` FOREIGN KEY (`team_a_id`) REFERENCES `teams_team` (`id`),
  CONSTRAINT `articles_post_team_b_id_10d6b1e5_fk_teams_team_id` FOREIGN KEY (`team_b_id`) REFERENCES `teams_team` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

我自己没有编写任何 SQL 文本文件。

我看到一个解决方案说 AUTO_INCREMENT 需要为 1 而不是 2,但我改变了它,它仍然没有任何区别。

【问题讨论】:

  • 版本不匹配?
  • 我确实遇到了导出不匹配的问题,但这是我修复的第一件事,我不再收到该错误

标签: mysql mysql-workbench


【解决方案1】:

在 MySQL WorkBench 中手动创建表后,我认为问题出在某些指定 DATETIME 长度为 (6) 的表中。在我手动创建的表中,它不接受 DATETIME(6),但接受了 DATETIME。

我认为这是导致问题的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 2014-07-05
    • 2021-06-25
    • 1970-01-01
    • 2018-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多