InnoDB: Error: Table “mysql”.”innodb_table_stats” not found.

1,Mysqldump的时候报错如下:

2014-05-05?14:12:37?7f004a9a2700?InnoDB:?Error:?Table?”MySQL”.”innodb_table_stats”?not?found.

但是show tables我看这个表示存在的:

但是show create table innodb_index_stats;报错如下:

  1. mysql>??show?create?table?innodb_index_stats;
  2. ERROR?1146?(42S02):?Table‘mysql.innodb_index_stats’?doesn’t?exist
  3. mysql>

 

2,估计是表坏了,去数据库服务器上面的mysql库的目录看下这些表的数据文件:

 

 

3,看到表的数据文件以及结构文件都存在

然后去找$MYSQL_HOME/share/mysql_system_tables.sql,search到建表语句

 

打开mysql_system_tables.sql,找到sql,然后执行:

  1. mysql>?CREATETABLE?IF?NOT?EXISTS?innodb_index_stats?(
  2. ????->?????????database_name???????????????????VARCHAR(64)?NOT?NULL,
  3. ????->?????????table_name??????????????????????VARCHAR(64)?NOT?NULL,
  4. ????->?????????index_name??????????????????????VARCHAR(64)?NOT?NULL,
  5. ????->?????????last_update?????????????????????TIMESTAMP?NOT?NULL?NOTNULL?DEFAULT?CURRENT_TIMESTAMP?ON?UPDATE?CURRENT_TIMESTAMP,
  6. ????->?????????stat_name???????????????????????VARCHAR(64)?NOT?NULL,
  7. ????->?????????stat_value??????????????????????BIGINT?UNSIGNED?NOT?NULL,
  8. ????->?????????sample_size?????????????????????BIGINT?UNSIGNED,
  9. ????->?????????stat_description????????????????VARCHAR(1024)?NOT?NULL,
  10. ????->?????????PRIMARY?KEY?(database_name,table_name,?index_name,?stat_name)
  11. ????->?)?ENGINE=INNODB?DEFAULT?CHARSET=utf8COLLATE=utf8_bin?STATS_PERSISTENT=0;
  12. ERROR?1146(42S02):?Table?‘mysql.innodb_index_stats’?doesn’t?exist
  13. mysql>
  14. mysql>

 

还报错Table ‘mysql.innodb_index_stats’ doesn’texist,可能是那个判断导致,去掉判断试试:

  1. mysql>?CREATETABLE?innodb_index_stats?(
  2. ????->????????database_name???????????????????VARCHAR(64)?NOT?NULL,
  3. ????->?????????table_name??????????????????????VARCHAR(64)?NOT?NULL,
  4. ????->?????????index_name??????????????????????VARCHAR(64)?NOT?NULL,
  5. ????->?????????last_update?????????????????????TIMESTAMP?NOT?NULL?NOTNULL?DEFAULT?CURRENT_TIMESTAMP?ON?UPDATE?CURRENT_TIMESTAMP,
  6. ????->?????????stat_name???????????????????????VARCHAR(64)?NOT?NULL,
  7. ????->?????????stat_value??????????????????????BIGINT?UNSIGNED?NOT?NULL,
  8. ????->?????????sample_size?????????????????????BIGINT?UNSIGNED,
  9. ????->?????????stat_description????????????????VARCHAR(1024)?NOT?NULL,
  10. ????->?????????PRIMARY?KEY?(database_name,table_name,?index_name,?stat_name)
  11. ????->?)?ENGINE=INNODB?DEFAULT?CHARSET=utf8COLLATE=utf8_bin?STATS_PERSISTENT=0;
  12. ERROR?1146(42S02):?Table?’mysql.innodb_index_stats’?doesn’t?exist

 

诡异,不存在还不让create了,是否原来的数据文件存在不过坏了,所以create的时候就报了这样一个诡异的错误呢?

 

4,去数据库目录看下,果然文件是否已经存在了:

  1. [root@xxx?mysql]#?ll?/home/data/mysql/data/mysql/innodb*
  2. -rw-rw—-.?1mysql?mysql??12982?4月???922:24?/home/data/mysql/data/mysql/innodb_index_stats.frm
  3. -rw-rw—-.?1mysql?mysql?180224?5月???6?10:38/home/data/mysql/data/mysql/innodb_index_stats.ibd
  4. -rw-rw—-.?1mysql?mysql???8830?4月???922:24?/home/data/mysql/data/mysql/innodb_table_stats.frm
  5. -rw-rw—-.?1mysql?mysql??98304?5月???610:38?/home/data/mysql/data/mysql/innodb_table_stats.ibd
  6. [root@xxx?mysql]#

如果是myisam表还可以用命令修复一下,但是innnodb,就只好重启数据库试试,restart之后,进入mysql库:

  1. mysql>?descinnodb_index_stats;
  2. ERROR?1146(42S02):?Table?‘mysql.innodb_index_stats’?doesn’t?exist

还是报错,那就只有drop操作:

  1. mysql>?droptable?mysql.innodb_index_stats;
  2. ERROR?1051(42S02):?Unknown?table?‘mysql.innodb_index_stats’
  3. mysql>
  4. mysql>

 

5,RM操作删除掉旧的坏的数据表文件

drop还是报错,最后看来只有一招了,rm -rf掉原来已经存在坏掉的不能加载的innodb_index_stats文件,再重新create了。

  1. rm?-rf/home/data/mysql/data/mysql/innodb*

rm后再登陆mysql执行create操作。

  1. mysql>?usemysql;
  2. Database?changed
  3. mysql>
  4. mysql>??CREATE?TABLE?innodb_index_stats?(
  5. ????->?????????????database_name???????????????????VARCHAR(64)?NOT?NULL,
  6. ????->?????????????table_name??????????????????????VARCHAR(64)?NOT?NULL,
  7. ????->?????????????index_name??????????????????????VARCHAR(64)?NOT?NULL,
  8. ????->?????????????last_update?????????????????????TIMESTAMP?NOT?NULL?NOTNULL?DEFAULT?CURRENT_TIMESTAMP?ON?UPDATE?CURRENT_TIMESTAMP,
  9. ????->?????????????stat_name???????????????????????VARCHAR(64)?NOT?NULL,
  10. ????->?????????????stat_value??????????????????????BIGINT?UNSIGNED?NOT?NULL,
  11. ????->?????????????sample_size?????????????????????BIGINT?UNSIGNED,
  12. ????->?????????????stat_description????????????????VARCHAR(1024)?NOT?NULL,
  13. ????->?????????????PRIMARY?KEY?(database_name,table_name,?index_name,?stat_name)
  14. ????->????)?ENGINE=INNODB?DEFAULT?CHARSET=utf8?COLLATE=utf8_binSTATS_PERSISTENT=0;
  15. Query?OK,?0?rowsaffected?(0.02?sec)

 

创建innodb_index_stats成功了。最后执行原来的mysqldump备份操作,一切正常。

搬瓦工,CN2高速线路,1GB带宽,电信联通优化KVM,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ,支持<支付宝> 【点击购买】!

Vultr$3.5日本节点,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快【点击购买】!

腾讯云云产品精选秒杀【点击购买】

阿里云香港、新加坡VPS/1核/1G/25G SSD/1T流量/30M带宽/年付¥288【点击购买】

百度云不止一折优惠【点击购买】

发表评论

电子邮件地址不会被公开。 必填项已用*标注