innodb_index_stats导入备份数据时报错表主键冲突的解决方法
故障描述
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,也有其他同行遇到了一样的错误
https://www.percona.com/forums/questions-discussions/mysql-and-percona-server/31971-mysql-innodb_index_stats-duplication-entry-error-on-restore
https://bugs.mysql.com/bug.php?id=71814
解决办法
1 mysqldump添加参数忽略这个表的备份
2 将备份文件中的这个表的insert改为replace
3 mysql -f强制导入
以上这篇innodb_index_stats导入备份数据时报错表主键冲突的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
上一篇: 海口十大小吃,椰子饭上榜,文昌鸡必吃
下一篇: shell获取命令行参数示例分享