如何查找mysql里面没有用到的索引。根据索引使用次数评估索引的必要性

方式1:可以借助开源pt-index-usage生成未使用索引报告
pt-index-usage --host=10.113.1.187 -P 3306 --user=dbazl --password=Dbazl_2023 /data/mysql/3306/logs/mysql.slow
工具可以再终端打印结果,也可以生成报告存到库中以便汇总分析

方式2:
通过MySQL自带系统数据字典表
performance_schema.table_io_waits_summary_by_index_usage
查找业务库中未被使用的索引,5.7后期版本可以直接通过sys库下的字典表进行查询
示例:(去除mysql系统库)
select object_schema,object_name,index_name from sys.schema_unused_indexes where object_schema not in(‘sys’,‘mysql’,‘performance_schema’,‘information_schema’);

以上供参考