【问题标题】:Importing database to Google Cloud SQL error: "mysql_query Duplicate entry '1' for key 'PRIMARY"将数据库导入 Google Cloud SQL 错误:“mysql_query Duplicate entry '1' for key 'PRIMARY”
【发布时间】:2015-10-23 01:29:00
【问题描述】:

我正在尝试将从本地 XAMPP 安装导出的 (Wordpress) 数据库导入 Google 云 SQL 数据库。

我按照Google documentation的步骤,完成了以下步骤:

  1. 我用 PHPmyadmin 从本地 XAMPP 导出了 .sql 文件(仅尝试了数据和结构和数据) 安装。
  2. 我创建了一个 Google Cloud 存储桶并上传了我的 .sql 文件。
  3. 我选择了我的实例并点击了“导入”
  4. 在bucket中插入文件.sql文件的路径
  5. 并指定了我的数据库

现在我收到以下错误:

mysql_query Duplicate entry '1' for key 'PRIMARY' (INSERT INTO 
`wp_comments` (`comment_ID`, `comment_post_ID`, `comment_author`, 
`comment_author_email`, `comment_author_url`, `comment_author_IP`, 
`comment_date`, `comment_date_gmt`, `comment_content`, `comment_karma`, 
`comment_approved`, `comment_agent`, `comment_type`, `comment_parent`, 
`user_id`) VALUES (1, 1, 'Mr WordPress', '', 'https://wordpress.org/', '', 
'2015-07-11 09:58:54', '2015-07-11 09:58:54', 'Hi, this is a comment.\nTo 
delete a comment, just log in and view the post's comments. There you will 
have the option to edit or delete them.', 0, 'post-trashed', '', '', 0, 0))

我在导入之前安装了一个 wordpress 数据库,所以也许我需要删除现有数据库,或者在上传新数据库之前将其留空?但在我看来,您通常可以通过现有数据库上传 .sql 文件,对吧?

【问题讨论】:

    标签: php mysql wordpress google-app-engine google-cloud-sql


    【解决方案1】:

    您需要删除所有表(清除数据库),然后导入该 .sql 文件。发生此错误是因为您已经有 wp_cmets 表并且它包含具有相同 ID 的注释。

    导入 SQL 文件,从不替换数据。如果重复记录将在主键下发生,它只会生成错误。

    【讨论】:

    • 感谢您的回答!我会试试的。
    猜你喜欢
    • 2019-12-21
    • 2018-12-01
    • 2021-10-07
    • 2019-10-11
    • 1970-01-01
    • 2013-09-09
    • 2021-01-22
    • 1970-01-01
    • 2016-07-05
    相关资源
    最近更新 更多