---
title: "[转载]【MySQL】【5.6.x InnoDB Error Table mysql.innodb_table_stats not found】"
author: "fall10"
date: "2017-03-04T12:19:45Z"
tags: []
categories: ["数据库"]
slug: "mysql-5-6-x-innodb-error-table-mysql-innodb-table-stats-not-found"
draft: false
lastmod: "2017-03-04T12:19:45Z"
id: 2360246
url: "https://fall10.iteye.com/blog/2360246"
---

【问题描述】：

检查error log的时候发现大量warnings：

\[Warning] InnoDB Error Table mysql.innodb\_index\_stats not found

\[Warning] InnoDB Error Table mysql.innodb\_table\_stats not found

\[Warning] InnoDB Error Table mysql.slave\_master\_info not found

\[Warning] InnoDB Error Table mysql.slave\_relay\_log\_info not found

\[Warning] InnoDB Error Table mysql.slave\_worker\_info not found

 

或在打开innodb表时，在err-log里会打印出：

 InnoDB: Error: Table "mysql"."innodb\_table\_stats" not found.

 Error: Fetch of persistent statistics requested for table "{databse\_name}"."{table\_name}" but the required system tables mysql.innodb\_table\_stats and mysql.innodb\_index\_stats are not present or have unexpected structure. Using transient stats instead.

 

【解决方案】：

先看看能否drop table，如果说表不存在，则继续下一步。

DROP TABLE mysql.innodb\_index\_stats;

DROP TABLE mysql.innodb\_table\_stats;

DROP TABLE mysql.slave\_master\_info;

DROP TABLE mysql.slave\_relay\_log\_info;

DROP TABLE mysql.slave\_worker\_info;

 

删除datadir下mysql数据库中的这五张表的frm文件（如有ibd也一并删除）

rm -rf $datadir/mysql/innodb\_index\_stats.*

rm -rf $datadir/mysql/innodb\_table\_stats.*

rm -rf $datadir/mysql/slave\_master\_info.*

rm -rf $datadir/mysql/slave\_relay\_log\_info.*

rm -rf $datadir/mysql/slave\_worker\_info.*

 

再执行如下语句，重新创建这五张表：

USE mysql;

 

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;

 

CREATE TABLE \`innodb\_table\_stats\` (

  \`database\_name\` varchar(64) COLLATE utf8\_bin NOT NULL,

  \`table\_name\` varchar(64) COLLATE utf8\_bin NOT NULL,

  \`last\_update\` timestamp NOT NULL DEFAULT CURRENT\_TIMESTAMP ON UPDATE CURRENT\_TIMESTAMP,

  \`n\_rows\` bigint(20) unsigned NOT NULL,

  \`clustered\_index\_size\` bigint(20) unsigned NOT NULL,

  \`sum\_of\_other\_index\_sizes\` bigint(20) unsigned NOT NULL,

  PRIMARY KEY (\`database\_name\`,\`table\_name\`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8\_bin STATS\_PERSISTENT=0;

 

CREATE TABLE \`slave\_master\_info\` (

  \`Number\_of\_lines\` int(10) unsigned NOT NULL COMMENT 'Number of lines in the file.',

  \`Master\_log\_name\` text CHARACTER SET utf8 COLLATE utf8\_bin NOT NULL COMMENT 'The name of the master binary log currently being read from the master.',

  \`Master\_log\_pos\` bigint(20) unsigned NOT NULL COMMENT 'The master log position of the last read event.',

  \`Host\` char(64) CHARACTER SET utf8 COLLATE utf8\_bin NOT NULL DEFAULT '' COMMENT 'The host name of the master.',

  \`User\_name\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'The user name used to connect to the master.',

  \`User\_password\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'The password used to connect to the master.',

  \`Port\` int(10) unsigned NOT NULL COMMENT 'The network port used to connect to the master.',

  \`Connect\_retry\` int(10) unsigned NOT NULL COMMENT 'The period (in seconds) that the slave will wait before trying to reconnect to the master.',

  \`Enabled\_ssl\` tinyint(1) NOT NULL COMMENT 'Indicates whether the server supports SSL connections.',

  \`Ssl\_ca\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'The file used for the Certificate Authority (CA) certificate.',

  \`Ssl\_capath\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'The path to the Certificate Authority (CA) certificates.',

  \`Ssl\_cert\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'The name of the SSL certificate file.',

  \`Ssl\_cipher\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'The name of the cipher in use for the SSL connection.',

  \`Ssl\_key\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'The name of the SSL key file.',

  \`Ssl\_verify\_server\_cert\` tinyint(1) NOT NULL COMMENT 'Whether to verify the server certificate.',

  \`Heartbeat\` float NOT NULL,

  \`Bind\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'Displays which interface is employed when connecting to the MySQL server',

  \`Ignored\_server\_ids\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'The number of server IDs to be ignored, followed by the actual server IDs',

  \`Uuid\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'The master server uuid.',

  \`Retry\_count\` bigint(20) unsigned NOT NULL COMMENT 'Number of reconnect attempts, to the master, before giving up.',

  \`Ssl\_crl\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'The file used for the Certificate Revocation List (CRL)',

  \`Ssl\_crlpath\` text CHARACTER SET utf8 COLLATE utf8\_bin COMMENT 'The path used for Certificate Revocation List (CRL) files',

  \`Enabled\_auto\_position\` tinyint(1) NOT NULL COMMENT 'Indicates whether GTIDs will be used to retrieve events from the master.',

  PRIMARY KEY (\`Host\`,\`Port\`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS\_PERSISTENT=0 COMMENT='Master Information';

 

CREATE TABLE \`slave\_relay\_log\_info\` (

  \`Number\_of\_lines\` int(10) unsigned NOT NULL COMMENT 'Number of lines in the file or rows in the table. Used to version table definitions.',

  \`Relay\_log\_name\` text CHARACTER SET utf8 COLLATE utf8\_bin NOT NULL COMMENT 'The name of the current relay log file.',

  \`Relay\_log\_pos\` bigint(20) unsigned NOT NULL COMMENT 'The relay log position of the last executed event.',

  \`Master\_log\_name\` text CHARACTER SET utf8 COLLATE utf8\_bin NOT NULL COMMENT 'The name of the master binary log file from which the events in the relay log file were read.',

  \`Master\_log\_pos\` bigint(20) unsigned NOT NULL COMMENT 'The master log position of the last executed event.',

  \`Sql\_delay\` int(11) NOT NULL COMMENT 'The number of seconds that the slave must lag behind the master.',

  \`Number\_of\_workers\` int(10) unsigned NOT NULL,

  \`Id\` int(10) unsigned NOT NULL COMMENT 'Internal Id that uniquely identifies this record.',

  PRIMARY KEY (\`Id\`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS\_PERSISTENT=0 COMMENT='Relay Log Information';

 

CREATE TABLE \`slave\_worker\_info\` (

  \`Id\` int(10) unsigned NOT NULL,

  \`Relay\_log\_name\` text CHARACTER SET utf8 COLLATE utf8\_bin NOT NULL,

  \`Relay\_log\_pos\` bigint(20) unsigned NOT NULL,

  \`Master\_log\_name\` text CHARACTER SET utf8 COLLATE utf8\_bin NOT NULL,

  \`Master\_log\_pos\` bigint(20) unsigned NOT NULL,

  \`Checkpoint\_relay\_log\_name\` text CHARACTER SET utf8 COLLATE utf8\_bin NOT NULL,

  \`Checkpoint\_relay\_log\_pos\` bigint(20) unsigned NOT NULL,

  \`Checkpoint\_master\_log\_name\` text CHARACTER SET utf8 COLLATE utf8\_bin NOT NULL,

  \`Checkpoint\_master\_log\_pos\` bigint(20) unsigned NOT NULL,

  \`Checkpoint\_seqno\` int(10) unsigned NOT NULL,

  \`Checkpoint\_group\_size\` int(10) unsigned NOT NULL,

  \`Checkpoint\_group\_bitmap\` blob NOT NULL,

  PRIMARY KEY (\`Id\`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS\_PERSISTENT=0 COMMENT='Worker Information';

 

最后重启mysqld即可。

 

 

可能形成这种问题的原因是做了形如rm -rf ibdata ib\_logfile0 等操作。