Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2759062
  • 博文数量: 587
  • 博客积分: 6356
  • 博客等级: 准将
  • 技术积分: 6410
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-23 10:54
个人简介

器量大者,福泽必厚

文章分类

全部博文(587)

文章存档

2019年(3)

2018年(1)

2017年(29)

2016年(39)

2015年(66)

2014年(117)

2013年(136)

2012年(58)

2011年(34)

2010年(50)

2009年(38)

2008年(16)

分类: LINUX

2015-11-14 16:31:10

场景:
zabbix 库挂掉了,不得已,只好重新将备份数据导入, 关键是我导入之前,删除了ibdata文件!
将sql导入后,发现mysql后台日志里面报错
InnoDB: Error: Table “mysql”.”innodb_table_stats” not found.
原因和解决方法如下:
MySQL 5.6的ibdata1表空间包含了5个InnoDB基础表,如下:
mysql> select table_name from information_schema.tables where table_schema='mysql' and engine='InnoDB';
+----------------------+
| table_name           |
+----------------------+
| innodb_index_stats   |
| innodb_table_stats   |
| slave_master_info    |
| slave_relay_log_info |
| slave_worker_info    |
+----------------------+
5 rows in set (0.00 sec)
在MySQL 5.6之前,如果关闭MySQL后删除ibdata1,再重新启动MySQL的时候ibdata1会被重新创建. 但从MySQL 5.6开始,这5个表不会被重建.
即使删除了ibdata1,下面的10个文件仍然保留在/var/lib/mysql/mysql中(假如datadir = /var/lib/mysql/):
innodb_index_stats.frm
innodb_index_stats.ibd
innodb_table_stats.frm
innodb_table_stats.ibd
slave_master_info.frm
slave_master_info.ibd
slave_relay_log_info.frm
slave_relay_log_info.ibd
slave_worker_info.frm
slave_worker_info.ibd


在安装MySQL 5.6,使用mysql_install_db做初始化的时候需要指定–defaults-file选项,按照自定义的my.cnf里面的参数去初始化,而不能
采用和5.5一样的方法删除之前的ibdata1文件后再重新生成新,因为MySQL 5.6在mysql系统库下引入上述的5个innodb表。否则启动mysqld
的时候会出现如下类似的Warnings:
MySQL运行中有写操作的时候还会出现大量的Errors.
...
2013-09-29 14:52:25 7f9b0ab03700 InnoDB: Error: Fetch of persistent statistics requested for table "yzs"."tb_qcard" 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.
2013-09-29 14:54:58 7f9d6dcdf700 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2013-09-29 14:54:58 7f9d6dcdf700 InnoDB: Error: Fetch of persistent statistics requested for table "yzs"."tb_topicrecord" 
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.
2013-09-29 14:56:14 7f9d6848f700 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2013-09-29 14:56:14 7f9d6848f700 InnoDB: Error: Fetch of persistent statistics requested for table 
"yzs"."groupproductstock" 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.
2013-09-29 14:56:14 7f9d6848f700 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2013-09-29 14:56:14 7f9d6848f700 InnoDB: Error: Fetch of persistent statistics requested for table "yzs"."groupstockcount" 
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.
...
消除这类错误的解决办法:


在另外的机器上安装MySQL服务器,使用相同my.cnf配置作为mysql_install_db做初始化时–defaults-file的选项.
初始化后启动MySQL,然后使用mysqldump导出这5个表:
#!/bin/bash
TABLELIST="innodb_index_stats"
TABLELIST="${TABLELIST} innodb_table_stats"
TABLELIST="${TABLELIST} slave_master_info"
TABLELIST="${TABLELIST} slave_relay_log_info"
TABLELIST="${TABLELIST} slave_worker_info"
mysqldump -uroot -p mysql ${TABLELIST} > mysql_innodb_tables.sql
将 mysql_innodb_tables.sql拷贝到出现坏表错误的那台数据库机器,并将其导入到系统库mysql库中.
# mysql -uroot -p mysql < mysql_innodb_tables.sql
运行FLUSH TABLES(可选)

摘之:  ##我个人非常喜欢的网站,向作者感谢!


mysql5.7下 解决该问题!
[ERROR] InnoDB: Table `mysql`.`innodb_index_stats` does not exist in the InnoDB internal data dictionary 
2017-03-21T00:34:36.498498Z 0 [ERROR] InnoDB: Table `mysql`.`innodb_table_stats` not found.
.....
2017-03-21T01:42:12.201897Z 0 [ERROR] InnoDB: Table `mysql`.`innodb_table_stats` not found.
2017-03-21T01:50:58.573120Z 167299 [ERROR] InnoDB: Table `mysql`.`innodb_table_stats` does not exist in the InnoDB internal data dictionary though MySQL is trying to drop it. Have you copied the .frm file of the table to the MySQL database directory from another database? Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
2017-03-21T01:56:00.609437Z 167348 [ERROR] InnoDB: Table `mysql`.`innodb_index_stats` does not exist in the InnoDB internal data dictionary though MySQL is trying to drop it. Have you copied the .frm file of the table to the MySQL database directory from another database? Please refer to http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting.html for how to resolve the issue.
mysql的日志文件里面有大量的上面的报警!
排查过程和解决方法:
1:登录mysql   后,use mysql;  desc innodb_table_stats;  发现找不到该表 ,想通过命令修复已经不可能了!
2: 试着执行drop table innodb_table_stats  ;   发现只能删除frm文件,ibd文件删除不了
3:于是不得已只好通过rm -f   innodb_table_stats.ibd 命令来删除该文件
删除后还要重建该文件,如何去找该文件对应的sql ?
cd  /usr/local/mysql/share
查到mysql_system_tables.sql 文件,将innodb_table_stats 相关sql给过滤出来!修改后
 CREATE TABLE innodb_table_stats (
        database_name                   VARCHAR(64) NOT NULL,
        table_name                      VARCHAR(64) NOT NULL,
        last_update                     TIMESTAMP NOT NULL NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        n_rows                          BIGINT UNSIGNED NOT NULL,
        clustered_index_size            BIGINT UNSIGNED NOT NULL,
        sum_of_other_index_sizes        BIGINT UNSIGNED NOT NULL,
        PRIMARY KEY (database_name, table_name)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0;

然后登录mysql ,执行该sql即可!



阅读(2926) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~