innodb_index_stats导入备份数据时报错表主键冲突的解决方法
故障描述
percona5.6,mysqldump全备份,导入备份数据时报错Duplicateentry'hoc_log99-item_log_27-PRIMARY-n_diff_pfx01'forkey'PRIMARY'
故障原因
查看了下这个主键应该是MySQL系统库下的系统表innodb_index_stats
mysql>showcreatetableinnodb_index_stats\G ***************************1.row*************************** Table:innodb_index_stats CreateTable:CREATETABLE`innodb_index_stats`( `database_name`varchar(64)COLLATEutf8_binNOTNULL, `table_name`varchar(64)COLLATEutf8_binNOTNULL, `index_name`varchar(64)COLLATEutf8_binNOTNULL, `last_update`timestampNOTNULLDEFAULTCURRENT_TIMESTAMPONUPDATECURRENT_TIMESTAMP, `stat_name`varchar(64)COLLATEutf8_binNOTNULL, `stat_value`bigint(20)unsignedNOTNULL, `sample_size`bigint(20)unsignedDEFAULTNULL, `stat_description`varchar(1024)COLLATEutf8_binNOTNULL, PRIMARYKEY(`database_name`,`table_name`,`index_name`,`stat_name`) )ENGINE=InnoDBDEFAULTCHARSET=utf8COLLATE=utf8_binSTATS_PERSISTENT=0 1rowinset(0.00sec) mysql>select*frominnodb_index_statswheredatabase_name='hoc_log99'andtable_name='item_log_27'andstat_name='n_diff_pfx01'andindex_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-0718:44:06|n_diff_pfx01|823672|20|redid| +---------------+-------------+------------+---------------------+--------------+------------+-------------+------------------+ 1rowinset(0.00sec)
再查看下我当时的备份文件sql的记录,发现再导入这个表之前是会重建表的,排除了再导入这个表之前,有item_log_27表的操作记录进了innodb_index_stats的可能。
--Tablestructurefortable`innodb_index_stats` DROPTABLEIFEXISTS`innodb_index_stats`; CREATETABLE`innodb_index_stats`( --Dumpingdatafortable`innodb_index_stats` LOCKTABLES`innodb_index_stats`WRITE; /*!40000ALTERTABLE`innodb_index_stats`DISABLEKEYS*/;
于是我又查看了下最近的binlog记录,发现确实有重建这个表的操作
DROPTABLEIFEXISTS`innodb_index_stats`/*generatedbyserver*/ CREATETABLE`innodb_index_stats`( /*!40000ALTERTABLE`innodb_index_stats`DISABLEKEYS*/
结论
mysql5.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
解决办法
1mysqldump添加参数忽略这个表的备份
2将备份文件中的这个表的insert改为replace
3mysql-f强制导入
以上这篇innodb_index_stats导入备份数据时报错表主键冲突的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。