2019独角兽企业重金招聘Python工程师标准>>>

错误日志:

[ERROR] Table vip_cube/imp_sup_dm_sup_brand_name_goods_online_half_hm contains 2 indexes inside InnoDB, which is different from the number of indexes 1 defined in the MySQL

存储引擎和Mysql服务层出现索引统计信息不一致,是否进行了DDL操作(创建了索引?出现这个错误,新创建的索引是否能使用?)

  • 问题重现:
root@localhost*5.5.48-log[test] >create table employees like employees.employees;
Query OK, 0 rows affected (0.21 sec)
root@localhost*5.5.48-log[test] > \! cp employees.frm employees.frm.old
root@localhost*5.5.48-log[test] >alter table employees add index idx_first_name(first_name);
Query OK, 0 rows affected (0.64 sec)
Records: 0 Duplicates: 0 Warnings: 0
root@localhost*5.5.48-log[test] >\! mv employees.frm.old employees.frm
root@localhost*5.5.48-log[test] >\! chown mysql.mysql employees.frm
root@localhost*5.5.48-log[test] >flush tables;
root@localhost*5.5.48-log[test] >select first_name from employees where first_name like 'a%' limit 1;
Empty set (0.00 sec)

查看错误日志:

[ERROR] Table test/employees contains 2 indexes inside InnoDB, which is different from the number of indexes 1 defined in the MySQL
root@localhost*5.5.48-log[test] >explain select first_name from employees where first_name like 'a%' limit 1;
+----+-------------+-----------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | employees | ALL | NULL | NULL | NULL | NULL | 1 | Using where |
+----+-------------+-----------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

可以看到语句是走不到索引的,语句分析和优化是mysql server完成?

  • 然后恢复创建索引后的frm文件:
root@localhost*5.5.48-log[test] > mv employees.frm.2 employees.frm – `employees.frm.2之前备份了`
root@localhost*5.5.48-log[test] >flush tables;
Query OK, 0 rows affected (0.02 sec)
root@localhost*5.5.48-log[test] >explain select first_name from employees where first_name like 'a%' limit 1;
+----+-------------+-----------+-------+----------------+----------------+---------+------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+-------+----------------+----------------+---------+------+------+--------------------------+
| 1 | SIMPLE | employees | index | idx_first_name | idx_first_name | 58 | NULL | 1 | Using where; Using index |
+----+-------------+-----------+-------+----------------+----------------+---------+------+------+--------------------------+
1 row in set (0.00 sec)
root@localhost*5.5.48-log[test] >alter table employees engine=innodb;
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0
root@localhost*5.5.48-log[test] >flush tables;
Query OK, 0 rows affected (0.04 sec)
root@localhost*5.5.48-log[test] >explain select first_name from employees where first_name like 'a%' limit 1;
+----+-------------+-----------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | employees | ALL | NULL | NULL | NULL | NULL | 1 | Using where |
+----+-------------+-----------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)

然后恢复有索引的frm文件

root@localhost*5.5.48-log[test] >flush tables;
Query OK, 0 rows affected (0.04 sec)
root@localhost*5.5.48-log[test] >show create table employees\G;
*************************** 1. row ***************************
Table: employees
Create Table: CREATE TABLE `employees` (
`emp_no` int(11) NOT NULL,
`birth_date` date NOT NULL,
`first_name` varchar(14) NOT NULL,
`last_name` varchar(16) NOT NULL,
`gender` enum('M','F') NOT NULL,
`hire_date` date NOT NULL,
PRIMARY KEY (`emp_no`),
KEY `idx_first_name` (`first_name`) – `索引是可以看到,查frm文件`
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
1 row in set (0.00 sec)
ERROR:
No query specified

但是日志会报如下错,说明存储引擎的索引已经在执行alter table employees engine=innodb;删除(重建表基于frm定义) :

160508 17:44:01 [ERROR] Table test/employees contains 1 indexes inside InnoDB, which is different from the number of indexes 2 defined in the MySQL
160508 17:44:01 [ERROR] Innodb could not find key n:o 1 with name idx_first_name from dict cache for table test/employees
160508 17:44:01 [ERROR] Table test/employees contains fewer indexes inside InnoDB than are defined in the MySQL .frm file. Have you mixed up .frm files from different installations? See http://dev.mysql.com/doc/refman/5.5/en/innodb-troubleshooting.html
  • 参考文档:

    • https://www.percona.com/blog/2011/11/29/innodb-vs-mysql-index-counts/
    • https://www.percona.com/doc/percona-server/5.1/management/innodb_fast_index_creation.html

转载于:https://my.oschina.net/anthonyyau/blog/674476

存储引擎和Mysql服务层出现索引信息不一致错误提示相关推荐

  1. MySQL InnoDB存储引擎 聚集和非聚集索引

    B+树索引 索引的目的在于提高查询效率,可以类比字典,如果要查"mysql"这个单词,我们肯定需要定位到m字母,然后从下往下找到y字母,再找到剩下的sql.如果没有索引,那么你可能 ...

  2. 存储引擎:MySQL系列之七

    一.MyISAM存储引擎 缺点: 不支持事务 最小粒度锁:表级 读写相互阻塞,写入不能读,读时不能写 不支持MVCC(支持多版本并发控制机制) 不支持聚簇索引 不支持数据缓存 不支持外键 崩溃恢复性较 ...

  3. mysql外键的存储引擎_10.mysql存储引擎

    2.1 存储引擎概述 和大多数的数据库不同, MySQL中有一个存储引擎的概念, 针对不同的存储需求可以选择最优的存储引擎. 存储引擎就是存储数据,建立索引,更新查询数据等等技术的实现方式 .存储引擎 ...

  4. 单机存储引擎到mysql的思考三

    上一篇我们阐述mysql锁机制以及MCVV多版本并发控制消除 读写阻塞本篇我们看看redo log.undo log以及bin log 标题 网址 单机存储引擎到mysql的思考一 https://b ...

  5. 单机存储引擎到mysql的思考一

    大家都知道mysql现在很火,很多招后端工程师的要求其中一项就是 精通mysql 但是我们真的了解mysql吗?那么笔者要下面卖膏药了~ 标题 网址 单机存储引擎到mysql的思考一 https:// ...

  6. 单机存储引擎到mysql的思考二

    上一篇中我们主要介绍mysql存储引擎物理结构进而引发对索引的 思考 但是并发事务和锁机制又是怎样的,下面我们来探索一下 标题 网址 单机存储引擎到mysql的思考一 https://blog.csd ...

  7. 运行mysql-front出现下面的错误提示:The evaluation time of this program has expired!

    运行mysql-front出现下面的错误提示:The evaluation time of this program has expired! The program will run in Lite ...

  8. MySQL Innodb存储引擎使用B+树做索引的优点

    对于数据库来说,索引和表数据都是存放在磁盘上的,一般使用B+树作为索引 MySQL Innodb存储引擎使用了B+树作为索引的优点,主要有以下原因: 1.索引和表数据都是存放在磁盘上的,如果磁盘上的数 ...

  9. mysql数据库恢复数据_【技术分享】使用Innodb存储引擎的mysql数据库恢复

    作者:维一零 预估稿费:400RMB(不服你也来投稿啊!) 投稿方式:发送邮件至linwei#360.cn,或登陆网页版在线投稿 前言 某天,在测试一张新数据表的字段时,由于在phpmyadmin不断 ...

最新文章

  1. 录制声音并且播放录取的声音
  2. mysql多实例(多个配置文件方式)
  3. 单例模式的3种实现方式, 及其性能对比
  4. 基于Shodan Python库的批量攻击实践 撒旦网
  5. CV:基于Keras利用CNN主流架构之mini_XCEPTION训练情感分类模型hdf5并保存到指定文件夹下
  6. 记sentinel里防止多并发下读取脏数据的操作
  7. 2017软件工程实践第二次作业
  8. 查看端口是否被占用,以及端口的应用名称
  9. Python函数的参数传递方式
  10. FPGA学习笔记---用Quartus II生成输入输出框图
  11. 关于Windows XP SP3 的 FAQ
  12. 使用Maven插件对项目进行打包
  13. masm32踩坑总结
  14. excel两个指标相关性分析_相关系数excel-如何用spss做相关性分析
  15. 计算机培训作息时间安排,985学霸作息时间表“走红”,网友:越努力,越幸运...
  16. 基于Web2.0的异构数字资源检索系统研究与开发
  17. html单页模板wap,单页模板html
  18. future.dj pro for Mac(专业DJ混音软件) 破解版
  19. 驾驶员理论考试通过!
  20. 关于js中e = e || window.event

热门文章

  1. 腾讯云VP王龙:与英特尔的合作将加速AI落地,硬件的灵活性要变得更强
  2. ARM发布自动驾驶芯片架构,重新宣示车载系统市场的主权
  3. Uber再受万点暴击:亚利桑那州无限期吊销其路测资格
  4. 对话彭军、楼教主:1.12亿美元融资来了,Pony.ai车队也已在路上 | 变局者
  5. postgresql 的 libdir 在哪里?
  6. [Vue warn]: Attribute id is ignored on component div because the component is a fragment instanc
  7. CCIE学习(4)——VLAN基础
  8. (八)java版spring cloud+spring boot+redis多租户社交电子商务平台 -SSO单点登录之OAuth2.0登录认证(2)...
  9. Linux下怎么使用任务管理器和真人接口源码出售进程管理
  10. 11.05T3 map