时间:2021-07-01 10:21:17 帮助过:19人阅读
故障描述
percona5.6,mysqldump全备份,导入备份数据时报错Duplicate entry 'hoc_log99-item_log_27-PRIMARY-n_diff_pfx01' for key 'PRIMARY'
故障原因
查看了下这个主键应该是MySQL系统库下的系统表innodb_index_stats
mysql> show create table innodb_index_stats\G *************************** 1. row *************************** Table: innodb_index_stats Create Table: CREATE TABLE `innodb_index_stats` ( `database_name` varchar(64) COLLATE utf8_bin NOT NULL, `table_name` varchar(64) COLLATE utf8_bin NOT NULL, `index_name` varchar(64) COLLATE utf8_bin NOT NULL, `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `stat_name` varchar(64) COLLATE utf8_bin NOT NULL, `stat_value` bigint(20) unsigned NOT NULL, `sample_size` bigint(20) unsigned DEFAULT NULL, `stat_description` varchar(1024) COLLATE utf8_bin NOT NULL, PRIMARY KEY (`database_name`,`table_name`,`index_name`,`stat_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0 1 row in set (0.00 sec) mysql> select * from innodb_index_stats where database_name='hoc_log99' and table_name='item_log_27' and stat_name='n_diff_pfx01' and index_name='PRIMARY'; +---------------+-------------+------------+---------------------+--------------+------------+-------------+------------------+ | database_name | table_name | index_name | last_update | stat_name | stat_value | sample_size | stat_description | +---------------+-------------+------------+---------------------+--------------+------------+-------------+------------------+ | hoc_log99 | item_log_27 | PRIMARY | 2016-10-07 18:44:06 | n_diff_pfx01 | 823672 | 20 | redid | +---------------+-------------+------------+---------------------+--------------+------------+-------------+------------------+ 1 row in set (0.00 sec)
再查看下我当时的备份文件sql的记录,发现再导入这个表之前是会重建表的,排除了再导入这个表之前,有item_log_27 表的操作记录进了innodb_index_stats的可能。
-- Table structure for table `innodb_index_stats` DROP TABLE IF EXISTS `innodb_index_stats`; CREATE TABLE `innodb_index_stats` ( -- Dumping data for table `innodb_index_stats` LOCK TABLES `innodb_index_stats` WRITE; /*!40000 ALTER TABLE `innodb_index_stats` DISABLE KEYS */;
于是我又查看了下最近的binlog记录,发现确实有重建这个表的操作
DROP TABLE IF EXISTS `innodb_index_stats` /* generated by server */ CREATE TABLE `innodb_index_stats` ( /*!40000 ALTER TABLE `innodb_index_stats` DISABLE KEYS */
结论
mysql 5.6的bug,也有其他同行遇到了一样的错误
www.percona.com/forums/questions-discussions/mysql-and-percona-server/31971-mysql-innodb_index_stats-duplication-entry-error-on-restore
bugs.mysql.com/bug.PHP?id=71814
解决办法
1 mysqldump添加参数忽略这个表的备份
2 将备份文件中的这个表的insert改为replace
3 mysql -f强制导入
【相关推荐】
1. Mysql免费视频教程
2. MySQL中添加新用户权限的实例详解
3. MySQL修改密码和访问限制的实例详解
4. 用正则表达式替换数据库中的内容的实例详 解
5. php将图片储存mysql中的实例详解
以上就是详解innodb_index_stats导入数据时提示表主键冲突的错误的详细内容,更多请关注Gxl网其它相关文章!