在查看MySQL错误日志的时候发现这样的错误,如下:

160322 21:42:59 [ERROR] Table baby/baby_order contains 12 indexes inside InnoDB, which is different from the number of indexes 11 defined in the My

SQL

大概意思是说表baby_order的索引数在InnoDB引擎内与索引数在mysql中定义的数量是不一致的

为什么会出现这样的错误呢?

参考了这篇文章的解释

https://www.percona.com/blog/2011/11/29/innodb-vs-mysql-index-counts/

I had a customer recently who a few strange errors in their mysqld.err log:

[ERROR] Table database_name/table_name contains 8 indexes inside InnoDB, which is different from the number of indexes 7 defined in the MySQL

1

[ERROR] Table database_name/table_name contains 8 indexes inside InnoDB, which is different from the number of indexes 7 defined in the MySQL

This customer was running Percona Server 5.1 and they got this error on two tables during a maintenance window when they were adding indexes to the same tables.

We had a suspicion that it had something to do with Fast index creation in Innodb, and that it had been corrected when the ALTER TABLE completed because the errors had not recurred.

Reproducing the error on a test system is simple:

复现这个错误的方法:

create an Innodb table

make a copy of the .frm file

do an ALTER TABLE to add an index

then copy the old .frm file back into place

re-open the table  (Might need a FLUSH TABLES or mysqld restart here)

From my testing, I saw that the error only happened when the table was opened and not on every table access.  So, it was a possibility that the indexes were out of sync and we weren’t seeing new errors in the log simply because the table hadn’t been re-opened.

But, before getting too crazy, how can we verify the problem still exists?  We need a way to compare the output of SHOW CREATE TABLE to what Innodb thinks.  What Innodb thinks is in the Innodb Data dictionary.

The first recommendation I got was to simply use the INFORMATION_SCHEMA.INNODB_SYS_INDEXES table, which exists in Percona Server 5.1, but doesn’t appear in MySQL until 5.6 (if the manual is to be trusted).  I’d probably consider this on a newer version of Percona Server or MysqL 5.6.

Another person (I’m looking at you, Baron) was adverse to trusting INNODB_SYS_INDEXES from some bad experiences with it, and suggested the Innodb Table monitor instead, see my next post for how that turned out, but this basically will regurgitate the entire Innodb Data dictionary to the mysqld error log file.

可以通过flush table1 table2 强制表关闭,然后重新打开表

If I had to do it over again, I think I’d simply try doing:  FLUSH TABLES table1, table2; to force the tables to close and be reopened and simply see if the error message comes back.  That might something of a performance impact, but it seems to be the most stable.

In this case, it turned out that the indexes were not out of sync, so I didn’t have to do anything to fix it.

However if I did have to fix it, I found on my test table that the extra index in Innodb could be removed by doing:

修复这个问题可以执行如下的语句更改表引擎为innodb

ALTER TABLE table_name ENGINE=Innodb;

This, of course, rebuilds the whole table based on the .frm table definition and removes the existing index in Innodb, which might not be desirable, but at least you can re-add it later.  However, it’s not the greatest thing to do on a live production database master if you can help it.

Another solution might be to figure out what index was missing via the Innodb data dictionary (more on that in a minute), create a separate table identical to the existing .frm, add that index to it, and copy the new .frm back over the original.  Kind of scary.

My advice is to ensure the error still exists before trying to fix it.

本文转自andylhz 51CTO博客,原文链接:http://blog.51cto.com/andylhz2009/1851161,如需转载请自行联系原作者

mysql5.5索引如何定义_MySQL5.5索引数在InnoDB引擎内与索引数在mysql中定义的数量是不一致问题-阿里云开发者社区...相关推荐

  1. mysql5.7 备份恢复_RDS for MySQL 5.7 备份恢复为本地实例-阿里云开发者社区

    RDS for MySQL 5.7 备份恢复为本地实例 近期同学咨询反馈 RDS for MySQL 5.7 备份恢复本地实例的问题比较多,提供一个恢复样例. 1. 本地环境 # 项目 说明 1 OS ...

  2. mysql join 索引 无效_ORACLE MYSQL中join 字段类型不同索引失效的情况-阿里云开发者社区...

    ORACLE MYSQL中join 字段类型不同索引失效的情况 重庆八怪 2016-12-29 780浏览量 简介: 关于JOIN使用不同类型的字段类型,数据库可能进行隐士转换,MYSQL ORACL ...

  3. MySQL创建索引-阿里云开发者社区

    如果你在查询时常用类似以下的语句: SELECT * FROM mytable WHERE category_id=1; 最直接的应对之道,是为category_id建立一个简单的索引: CREATE ...

  4. typescript索引类型_复杂场景下的 typescript 类型锚定 (1) ----- 对象索引提取-阿里云开发者社区...

    前言:在编写 typescript 应用的时候,有时候我们会希望复用或者构造一些特定结构的类型,这些类型只从 typescript 靠内建类型和 interface.class 比较难以表达,这时候我 ...

  5. mysql 视图会走索引吗_MySQL视图索引与存储过程精析-阿里云开发者社区

    1.MySQL分页查询 1.1 limit函数: SELECT * FROM emp LIMIT 3 –只查询三条数据,其他忽略 1.2 select * from emp order by empn ...

  6. python列表索引超出范围 等于啥_python如何解决IndexError:列表索引超出范围?-问答-阿里云开发者社区-阿里云...

    我正在尝试为ucf101数据集生成密集流,但我不断收到以下错误: 我尝试在第68行中将video_name.split('')[1]更改为video_name.split('')[0],已编译代码,但 ...

  7. mysql5.7.10安装_MySQL5.7.10下载及安装及配置-阿里云开发者社区

    MySQL5.7.10下载及安装及配置 一.下载 自MySQL版本升级到5.7以后,其安装及配置过程和原来版本发生了很大的变化,下面详细介绍5.7版本MySQL的下载.安装及配置过程. 图1.1 My ...

  8. mysql cmake错误_MySQL5.5安装出现CMake错误找不到CMakelists.txt原因-阿里云开发者社区...

    今天虚拟机上测试安装 CentOS6.3 + PHP5.4.8 + MySQL5.5.28,结果捣鼓了半天 MySQL都没装上,老是CMake目录下找不到那个 lists 文件,郁闷的不行,最后发现问 ...

  9. 从python菜鸟到kaggle_Kaggle首次定义数据科学家:30岁,年薪5万刀,爱Python,最恨脏数据-阿里云开发者社区...

    今日凌晨,全球最大的数据科学社群Kaggle发布了第一份数据科学/机器学习业界现状调查报告.这份调查问卷的受访者囊括了来自50多个国家的16,000+位从业者,根据他们的问卷结果,Kaggle给出了一 ...

最新文章

  1. 6 款 Java 8 自带工具,轻松分析定位 JVM 问题!
  2. class文件打成jar包
  3. 在WIN7下硬盘安装XP双系统
  4. 终于明白上一篇的一顿误操作是什么了,是$,不是S !!!!!
  5. python创建矩阵_Python创建二维数组的正确姿势
  6. LLVM和clang
  7. CCF NOI1139 高精度减法
  8. 数据库系统工程师考点
  9. 台湾省谷歌高清卫星地图下载
  10. 能源DEA--对于业务和环境评估的规模报酬与规模损害
  11. 订单审批流程 数据库表设计
  12. windows桌面图标全部不见了怎么办
  13. 讲给后台程序员看的前端系列教程(17)——文本样式
  14. 周期性行业是什么意思_周期性股票是什么意思 周期性股票的特征有哪些
  15. 移动端html5广告的优势,移动端H5广告的互动类型探析
  16. DC算法竞赛——员工离职预测
  17. prometheus 告警配置以及配置项解释
  18. html 调用es2015模块,在浏览器中懒加载ES2015模块
  19. python-套接字基础与 UDP 通信
  20. 微软自动调参工具—NNI安装与快速上手,AutoML必备工具

热门文章

  1. php递归实现层级树状展开,PHP递归实现层级树状展开,php递归层级树状_PHP教程...
  2. 手写一个网关服务,理解更透彻!
  3. SQL Server 2008 R2 安装
  4. Linux centos7 安装python3.6.5 和 pip3
  5. java学习笔记之DBUtils工具包
  6. 常用docker命令
  7. javascript调用服务端验证控件
  8. 页面缓存,数据源缓存
  9. 7-Spring Boot的安全管理
  10. 6-Spring Boot缓存管理