数据库
首页 > 数据库> > mysqldump auto_increment导致主键错误

mysqldump auto_increment导致主键错误

作者:互联网

我正在使用mysqldump(a)转储表,然后(b)将其插入其他地方.当我尝试执行部分(b)时出现问题.这是我得到的错误.

密钥“ PRIMARY”的条目“ 1”重复

现在,等等,等等.我知道我不会插入重复的主键….我检查了CREATE TABLE语句. id字段上的auto_incremement保留为id列的最大值:AUTO_INCREMENT = 45634650.我认为问题在于,如果您尝试插入ID值小于…..中指定的auto_increment值的任何行,则无论该ID是否重复,MySQL都会给出此错误.

我尝试从TABLE CREATE语句中手动删除AUTO_INCREMENT.同样的错误.

更新:这是Create table语句的一些相关部分.除去插入物,甚至其中之一也是巨大的:

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
/*Table structure for table `WC_ip` */

DROP TABLE IF EXISTS `WC_ip`;

CREATE TABLE `WC_ip` (
  `id` int(11) NOT NULL AUTO_INCREMENT,

etc etc .. =)

  `activity_date` date DEFAULT NULL,
  UNIQUE KEY `userid_game_installAge` (`userid`,`game`,`install_age`),
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=45750081 DEFAULT CHARSET=latin1;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

INSERT INTO `bi_user_daily` VALUES (1,1512489,'WC','1','GR','100001229652633','asfdasdf','http://www.facebook.com/asfdasdfasdffgdf','notif','gghgf','Secondary Paid Direct','2012-01-02',0,0,0.00,0,0,0,0,194,0,0,1325491229,'Google Chrome','16.0.912.63','windows','GR','178.146.208.153',0,1325491253,24,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'incomplete',91,2,1914,2,1,3.23,0,NULL,NULL,NULL,NULL,0,'2012-01-03','2012-01-03 07:06:57','2012-01-02'),

(2,1512490,'WC','1','TW','453','asdf','http://www.facebook.com/profile.php?id=blachdfhjdfkh','dfdsfg','','Primary Paid','2012-01-02',0,0,0.00,0,0,0,0,394,0,0,1325491233,'Google Chrome','16.0.912.63','windows','TW','114.41.159.234',0,1325491258,25,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'complete',120,2,2302,2,1,6.57,0,NULL,NULL,NULL,NULL,0,'2012-01-03','2012-01-03 07:06:57','2012-01-02'),

(3,1512491,'WC','1','','1590571243','','','notif','asfd','Secondary Paid Direct','2012-01-02',0,0,0.00,0,0,0,0,0,0,0,34535,'Mozilla Firefox','9.0.1','windows','-','10.54.48.31',1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0.00,0,NULL,NULL,NULL,NULL,0,'2012-01-03','2012-01-03 07:06:57','2012-01-02')

CREATE TABLE `bi_user_daily` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `userid` bigint(20) DEFAULT NULL,
  `game` varchar(45) DEFAULT NULL,
  `main.install_today` varchar(45) DEFAULT NULL,
  `main.country` text,
  `main.fbid` varchar(50) DEFAULT NULL,
  `main.photo` text,
  `main.main.url` text,
  `main.fromstr` varchar(50) DEFAULT NULL,
  `main.sourcestr` varchar(50) DEFAULT NULL,
  `main.user_type` varchar(50) DEFAULT NULL,
  `main.install_date_pst` date DEFAULT NULL,
  `main.install_hour_pst` int(11) DEFAULT NULL,
  `main.revenue_primary` int(11) DEFAULT NULL,
  `main.revenue_secondary` decimal(10,2) DEFAULT NULL,
  `main.trans_primary` int(11) DEFAULT NULL,
  `main.trans_secondary` int(11) DEFAULT NULL,
  `main.direct_installs_generated` int(11) DEFAULT NULL,
  `main.indirect_installs_generated` int(11) DEFAULT NULL,
  `main.timeplayed_total` int(11) DEFAULT NULL,
  `main.gift_sent_total` int(11) DEFAULT NULL,
  `main.monetized` int(11) DEFAULT NULL,
  `install.usercreate_time` int(11) DEFAULT NULL,
  `install.browser` varchar(75) DEFAULT NULL,
  `install.browser_version` varchar(50) DEFAULT NULL,
  `install.os` varchar(50) DEFAULT NULL,
  `install.ip_address_country` varchar(50) DEFAULT NULL,
  `install.ip_address` varchar(50) DEFAULT NULL,
  `install.noload` int(11) DEFAULT NULL,
  `install.f.reate_time` int(11) DEFAULT NULL,
  `install.load_duration` int(11) DEFAULT NULL,
  `l.f.time_saved` int(11) DEFAULT NULL,
  `l.f.playerLevel` int(11) DEFAULT NULL,
  `l.f.daysSinceInstall` int(11) DEFAULT NULL,
  `l.f.resource1` int(11) DEFAULT NULL,
  `l.f.resource2` int(11) DEFAULT NULL,
  `l.f.resource3` int(11) DEFAULT NULL,
  `l.f.resource4` int(11) DEFAULT NULL,
  `l.f.f.epairTime` int(11) DEFAULT NULL,
  `l.f.dockRepairTime` int(11) DEFAULT NULL,
  `l.f.fleetRepairTime` int(11) DEFAULT NULL,
  `l.f.maxResearchTime` int(11) DEFAULT NULL,
  `l.f.shipBuildTime` int(11) DEFAULT NULL,
  `l.f.buildingUpgradeTime` int(11) DEFAULT NULL,
  `l.f.numf.Uncovered` int(11) DEFAULT NULL,
  `l.f.attackablef.Uncovered` int(11) DEFAULT NULL,
  `l.f.numTerrainsUncovered` int(11) DEFAULT NULL,
  `l.f.numFleets` int(11) DEFAULT NULL,
  `l.f.battlesWon` int(11) DEFAULT NULL,
  `l.f.battlesTotal` int(11) DEFAULT NULL,
  `l.f.numf.ttacks` int(11) DEFAULT NULL,
  `l.f.numf.efends` int(11) DEFAULT NULL,
  `l.f.totalResourcesCombat` int(11) DEFAULT NULL,
  `l.f.totalResourcesProduced` int(11) DEFAULT NULL,
  `l.f.bubbleTimeLeft` int(11) DEFAULT NULL,
  `l.f.FBCSpend` int(11) DEFAULT NULL,
  `l.f.numFriends` int(11) DEFAULT NULL,
  `l.f.numInstallsGenerated` int(11) DEFAULT NULL,
  `l.f.numGiftsRecd` int(11) DEFAULT NULL,
  `l.f.numChatMessagesSent` int(11) DEFAULT NULL,
  `l.f.numMissionsCompleted` int(11) DEFAULT NULL,
  `l.f.numAdvancedResearched` int(11) DEFAULT NULL,
  `l.f.numWeaponsResearched` int(11) DEFAULT NULL,
  `l.f.numArmorsResearched` int(11) DEFAULT NULL,
  `l.f.numHullsResearched` int(11) DEFAULT NULL,
  `l.summary.tutorial_status` varchar(50) DEFAULT NULL,
  `l.summary.tutorial_stage` int(11) DEFAULT NULL,
  `l.summary.user_level` int(11) DEFAULT NULL,
  `l.summary.f.points` int(11) DEFAULT NULL,
  `l.summary.f.loads` int(11) DEFAULT NULL,
  `key_metrics.logged_in` int(11) DEFAULT NULL,
  `key_metrics.timeplayed` decimal(10,2) DEFAULT NULL,
  `key_metrics.revenue` int(11) DEFAULT NULL,
  `virality.secondary_direct_install` int(11) DEFAULT NULL,
  `virality.secondary_indirect_install` int(11) DEFAULT NULL,
  `monetization.secondary_direct_revenue` decimal(10,2) DEFAULT NULL,
  `monetization.secondary_indirect_revenue` decimal(10,2) DEFAULT NULL,
  `install_age` int(11) DEFAULT NULL,
  `record_created_date` date DEFAULT NULL,
  `record_created_datetime` datetime DEFAULT NULL,
  `activity_date` date DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `userid_game_installAge` (`userid`,`game`,`install_age`)
) ENGINE=MyISAM AUTO_INCREMENT=45634650 DEFAULT CHARSET=latin1;

解决方法:

几个月前,我遇到了同样的问题(在我的blog上发布了解决方案).在MySQL 5.1.11中有一个known issue,如果您执行mysqldump,它还会输出auto_increment计数(如您在帖子中所述).您可以使用sed(流编辑)并在生成转储文件时解析出auto_increment构造:

mysqldump -u username -p -h <db-host> --opt <db-name> -d --single-transaction | sed 's/ AUTO_INCREMENT=[0-9]*\b//' > <filename>.sql

标签:primary-key,mysqldump,auto-increment,mysql,duplicates
来源: https://codeday.me/bug/20191101/1986732.html