导入WordPress数据库 - #1075 - 表定义不正确;只能有一个自动列,必须将其定义为键

问题描述 投票:4回答:5

我正在尝试使用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;

所以我尝试了在Google上提到的解决方案

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_comments的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 table中看到alter table部分中的信息并且不知道id我应该将它复制到创建部分或者什么。

有人可以提供一些提示,说明为什么会这样。

谢谢。

mysql wordpress phpmyadmin
5个回答
3
投票

对于每个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

2
投票

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

您可以尝试'Adminer',这是一个功能强大的phpmyadmin替代方案,它只基于一个文件!

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

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

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


1
投票

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


0
投票

这个问题由phpMyAdmin(PMA)记录并且通过基本上说你不能在MySQL 5.0中使用当前版本来“修复”。

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

发现我的服务器运行PMA 4.3与MYSQL 5.0.95,而我的本地是MYSQL 5.5。我现在不知道为什么这是一个问题,因为旧的PMA会像mysqldump那样导入/导出很好,我猜他们改变并简化了语法,因为这是合法的表演原因。


0
投票

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

这对我有用:

您导出的SQL在底部附近有一堆语句“ALTER”您在顶部创建的所有表。您需要做的就是复制到上面的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导入新数据库,则必须手动编辑SQL。如果你有很多桌子和/或网站受到这个“虫子”的影响,那么它需要一些时间,所以你可以喝咖啡,无论做什么工作,然后解决它,继续你的生活。

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

由于新PMA / MySQL中的性能“增强”,所有这一切都令人头痛。骗子!

© www.soinside.com 2019 - 2024. All rights reserved.