【问题标题】:Importing WordPress Database - #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key导入 WordPress 数据库 - #1075 - 表定义不正确;只能有一个自动列,并且必须将其定义为键
【发布时间】:2015-11-17 19:09:20
【问题描述】:

我正在尝试使用 phpMyAdmin 将 WordPress 数据库从 Plesk 移动到 cPanel,但导入时出现以下错误:

SQL query:

Table structure for table `wp_commentmeta`

CREATE TABLE IF NOT EXISTS  `wp_commentmeta` (

 `meta_id` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
 `comment_id` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT  '0',
 `meta_key` VARCHAR( 255 ) DEFAULT NULL ,
 `meta_value` LONGTEXT
) ENGINE = MYISAM AUTO_INCREMENT =236 DEFAULT CHARSET = utf8;

MySQL said: Documentation

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

我像往常一样使用快速选项导出数据库,然后进行正常导入。

sql导出的相关部分是:

--
-- Table structure for table `wp_commentmeta`
--

CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
  `meta_id` bigint(20) unsigned NOT NULL auto_increment,
  `comment_id` bigint(20) unsigned NOT NULL default '0',
  `meta_key` varchar(255) default NULL,
  `meta_value` longtext
) ENGINE=MyISAM AUTO_INCREMENT=236 DEFAULT CHARSET=utf8;

所以我尝试了谷歌上提到的解决方案

CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
  `meta_id` bigint(20) unsigned NOT NULL PRIMARY KEY auto_increment,
  `comment_id` bigint(20) unsigned NOT NULL default '0',
  `meta_key` varchar(255) default NULL,
  `meta_value` longtext
) ENGINE=MyISAM AUTO_INCREMENT=236 DEFAULT CHARSET=utf8;

这次我得到了这个错误:

SQL query:

CREATE TABLE IF NOT EXISTS  `wp_comments` (

 `comment_ID` BIGINT( 20 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
 `comment_post_ID` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT  '0',
 `comment_author` TINYTEXT NOT NULL ,
 `comment_author_email` VARCHAR( 100 ) NOT NULL DEFAULT  '',
 `comment_author_url` VARCHAR( 200 ) NOT NULL DEFAULT  '',
 `comment_author_IP` VARCHAR( 100 ) NOT NULL DEFAULT  '',
 `comment_date` DATETIME NOT NULL DEFAULT  '0000-00-00 00:00:00',
 `comment_date_gmt` DATETIME NOT NULL DEFAULT  '0000-00-00 00:00:00',
 `comment_content` TEXT NOT NULL ,
 `comment_karma` INT( 11 ) NOT NULL DEFAULT  '0',
 `comment_approved` VARCHAR( 20 ) NOT NULL DEFAULT  '1',
 `comment_agent` VARCHAR( 255 ) NOT NULL DEFAULT  '',
 `comment_type` VARCHAR( 20 ) NOT NULL DEFAULT  '',
 `comment_parent` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT  '0',
 `user_id` BIGINT( 20 ) UNSIGNED NOT NULL DEFAULT  '0'
) ENGINE = MYISAM AUTO_INCREMENT =226 DEFAULT CHARSET = utf8;

MySQL said: Documentation

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key 

wp_cmets 的 CREATE 部分如下。

DROP TABLE IF EXISTS `wp_comments`;
CREATE TABLE IF NOT EXISTS `wp_comments` (
  `comment_ID` bigint(20) unsigned NOT NULL auto_increment,
  `comment_post_ID` bigint(20) unsigned NOT NULL default '0',
  `comment_author` tinytext NOT NULL,
  `comment_author_email` varchar(100) NOT NULL default '',
  `comment_author_url` varchar(200) NOT NULL default '',
  `comment_author_IP` varchar(100) NOT NULL default '',
  `comment_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `comment_date_gmt` datetime NOT NULL default '0000-00-00 00:00:00',
  `comment_content` text NOT NULL,
  `comment_karma` int(11) NOT NULL default '0',
  `comment_approved` varchar(20) NOT NULL default '1',
  `comment_agent` varchar(255) NOT NULL default '',
  `comment_type` varchar(20) NOT NULL default '',
  `comment_parent` bigint(20) unsigned NOT NULL default '0',
  `user_id` bigint(20) unsigned NOT NULL default '0'
) ENGINE=MyISAM AUTO_INCREMENT=226 DEFAULT CHARSET=utf8;

转储底部是以下 auto_increment 信息。

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `wp_commentmeta`
--
ALTER TABLE `wp_commentmeta`
AUTO_INCREMENT=236;
--
-- AUTO_INCREMENT for table `wp_comments`
--
ALTER TABLE `wp_comments`
AUTO_INCREMENT=226;
--
-- AUTO_INCREMENT for table `wp_event_list`
--
ALTER TABLE `wp_event_list`
AUTO_INCREMENT=9;
--
-- AUTO_INCREMENT for table `wp_layerslider`
--
ALTER TABLE `wp_layerslider`
AUTO_INCREMENT=6;
--
-- AUTO_INCREMENT for table `wp_options`
--
ALTER TABLE `wp_options`
AUTO_INCREMENT=497473;
--
-- AUTO_INCREMENT for table `wp_postmeta`
--
ALTER TABLE `wp_postmeta`
AUTO_INCREMENT=18312;
--
-- AUTO_INCREMENT for table `wp_posts`
--
ALTER TABLE `wp_posts`
AUTO_INCREMENT=2083;
--
-- AUTO_INCREMENT for table `wp_terms`
--
ALTER TABLE `wp_terms`
AUTO_INCREMENT=136;
--
-- AUTO_INCREMENT for table `wp_term_taxonomy`
--
ALTER TABLE `wp_term_taxonomy`
AUTO_INCREMENT=137;
--
-- AUTO_INCREMENT for table `wp_usermeta`
--
ALTER TABLE `wp_usermeta`
AUTO_INCREMENT=1527;
--
-- AUTO_INCREMENT for table `wp_users`
--
ALTER TABLE `wp_users`
AUTO_INCREMENT=43;
--
-- AUTO_INCREMENT for table `wp_woocommerce_attribute_taxonomies`
--
ALTER TABLE `wp_woocommerce_attribute_taxonomies`
AUTO_INCREMENT=5;
--
-- AUTO_INCREMENT for table `wp_woocommerce_order_itemmeta`
--
ALTER TABLE `wp_woocommerce_order_itemmeta`
AUTO_INCREMENT=1869;
--
-- AUTO_INCREMENT for table `wp_woocommerce_order_items`
--
ALTER TABLE `wp_woocommerce_order_items`
AUTO_INCREMENT=294;
--
-- AUTO_INCREMENT for table `wp_woocommerce_tax_rates`
--
ALTER TABLE `wp_woocommerce_tax_rates`
AUTO_INCREMENT=4;
--
-- AUTO_INCREMENT for table `wp_woocommerce_termmeta`
--
ALTER TABLE `wp_woocommerce_termmeta`
AUTO_INCREMENT=116;

这就是我真正陷入困境的地方,因为我迅速突然地达到了我的知识极限,不想让事情变得更糟。我习惯于在 create 中查看 alter table 部分中的信息,但不知道我应该将其复制到 create 部分中还是什么。

有人可以提供一些关于为什么会发生这种情况的提示吗?

谢谢。

【问题讨论】:

  • 您没有在创建查询中定义键和索引
  • 我完成了创建查询并在底部添加了来自插入查询的信息,它正在工作。

标签: mysql wordpress phpmyadmin


【解决方案1】:

我从另一个phpMyAdmin导出时遇到同样的问题,文件mysql导出不包含主键,然后在导出时我选择了方法“自定义-显示所有可能的选项”,然后我检查了“IF NOT EXISTS(效率较低,因为在创建表期间会生成索引)”。然后导出的文件在文件中包含主键。我的问题解决了。我希望这对你有帮助。

【讨论】:

    【解决方案2】:

    您可能使用了两种不同版本的 phpmyadmin,一种在 plesk 中,另一种在您的 cpanel 系统中?

    您可以尝试“Adminer”,这是一个强大的 phpmyadmin 替代方案,它仅基于一个文件!

    从这里下载:http://www.adminer.org/en/

    将 adminer.php 复制到要从中导出导出的服务器以及要导入 sql 数据的服务器。

    转到您的网站/adminer.php 并使用您拥有的凭据登录到您的数据库。导出和导入与 phpmyadmin 类似,但优点是您使用的是一种通用版本的管理软件,可确保导入和导出正常运行。

    【讨论】:

      【解决方案3】:

      如果您像我一样,从 MySQL 5.5(托管服务器)导出表并尝试导入 MySQL 5.6(Mac 上的 XAMPP),却遇到了可怕的 1075 错误。在互联网上搜索了几个小时后,您发现它与自动增量和主键有关。不是数据库程序员,这些信息(由上面的 liquified 链接提供)无助于解决问题,因为您基本上被告知:“嘿,不要那样做”。嗯,先生。 PMA bug,已经解决了,怎么修复呢?

      这对我有用:

      您导出的 SQL 在底部附近有一堆语句,用于“更改”您在顶部创建的所有表。您需要做的就是复制到上面的 CREATE 语句中。

      因此,在底部,您的 ALTER wp_commentmeta 如下所示:

      ALTER TABLE `wp_commentmeta`
        ADD PRIMARY KEY  (`meta_id`),
        ADD KEY `comment_id` (`comment_id`),
        ADD KEY `meta_key` (`meta_key`);
      

      在顶部,CREATE 看起来像这样:

      CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
        `meta_id` bigint(20) unsigned NOT NULL auto_increment,
        `comment_id` bigint(20) unsigned NOT NULL default '0',
        `meta_key` varchar(255) default NULL,
        `meta_value` longtext
      ) TYPE=MyISAM AUTO_INCREMENT=67;
      

      解决办法是去掉底部的ALTER,把这些语句放到CREATE中,像这样(在'longtext'后面加逗号):

      CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
        `meta_id` bigint(20) unsigned NOT NULL auto_increment,
        `comment_id` bigint(20) unsigned NOT NULL default '0',
        `meta_key` varchar(255) default NULL,
        `meta_value` longtext,
      PRIMARY KEY (`meta_id`),
        KEY `comment_id` (`comment_id`),
        KEY `meta_key` (`meta_key`)
      ) TYPE=MyISAM AUTO_INCREMENT=67;
      

      现在,如果你使用它,你会因为语法错误而收到 1064 错误。男人可以休息吗?您仍然需要为这个新版本更改 MyISAM 内容:

      TYPE=MyISAM AUTO_INCREMENT=67;
      

      改成

      ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=67;
      

      最后,您的最终 CREATE 声明将如下所示,并且您的 SQL 底部不需要任何 ALTER 表语句:

      CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
        `meta_id` bigint(20) unsigned NOT NULL auto_increment,
        `comment_id` bigint(20) unsigned NOT NULL default '0',
        `meta_key` varchar(255) default NULL,
        `meta_value` longtext,
        PRIMARY KEY (`meta_id`),
        KEY `comment_id` (`comment_id`),
        KEY `meta_key` (`meta_key`)
      ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=50 ;
      

      是的,如果您打算将 SQL 导入新数据库,则必须手动编辑它。如果您有很多表格和/或网站受到此“错误”的影响,这将需要一些时间,所以请喝杯咖啡,无论什么可行的,然后修复它并继续您的生活。

      现在,如果您仍然遇到错误,请检查您的语法,确保在从 ALTER 表中复制时删除“ADD”。消除 ';'并正确使用逗号。如果您设法导入部分数据库、一些表,但在语法上遇到问题,请转储所有表并在修复后再次尝试导入。我遇到了 1062: duplicate primary key 因为我设法导入了一些表而其他表失败了。当我再次尝试导入时,已经为表设置了主键。

      由于新 PMA/MySQL 中的性能“增强”,所有这些令人头疼的问题。骗子!

      【讨论】:

        【解决方案4】:

        phpMyAdmin (PMA) 记录了这个问题,并通过实质上说您不能将当前版本与 MySQL 5.0 一起“修复”。

        使用 auto_increment 导出表,主键创建无效语句 > 由于缺少支持的最低 MySQL 版本而导致的问题

        发现我的服务器正在运行带有 MYSQL 5.0.95 的 PMA 4.3,而我的本地服务器是 MYSQL 5.5。我不知道为什么现在这是个问题,因为旧的 PMA 会像 mysqldump 一样漂亮地导入/导出,我猜他们出于性能原因更改并简化了语法,这是合法的。

        【讨论】:

          【解决方案5】:

          对于每个 Wordpress 表格,以这种方式添加其键(见倒数第二行):

          CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
            `meta_id` bigint(20) unsigned NOT NULL auto_increment,
            `comment_id` bigint(20) unsigned NOT NULL default '0',
            `meta_key` varchar(255) default NULL,
            `meta_value` longtext,
            key (meta_id) -- add this line (remember to add the comma in the previous line)
          ) ENGINE=MyISAM AUTO_INCREMENT=236 DEFAULT CHARSET=utf8;
          

          Wordpress 表格:

          wp_commentmeta
          wp_comments
          wp_links
          wp_options
          wp_postmeta
          wp_posts
          wp_terms
          wp_term_relationships
          wp_term_taxonomy
          wp_usermeta
          wp_users
          

          【讨论】:

            猜你喜欢
            • 2013-07-12
            • 2017-05-31
            • 2013-12-17
            • 1970-01-01
            • 2019-01-02
            • 2015-04-05
            • 1970-01-01
            • 1970-01-01
            • 2020-01-01
            相关资源
            最近更新 更多