展开全部
在一个生产库上,没有创建索引,是不可思议的,当然你的索引创e68a84e8a2ad62616964757a686964616f31333363373765建的太多了、冗余了,更是不可思议的。恰当的索引能够提高你的数据库性能,反之则提高维护成本,下面就介绍一款工具,来分析你的mysql库的索引是不是有冗余,pt-duplicate-key-checker,它能从mysql表中找出重复的索引和外键,这个工具会将重复的索引和外键都列出来,并生成删除重复索引的语句,非常方便。工具详细介绍请参考
官文:
直接上实例:
[root@localhost bin]# ./pt-duplicate-key-checker -h192.168.2.88
-unigel -p123456 -dnigel
#
########################################################################
#
nigel.a1
#
########################################################################
# dx_cd is a left-prefix of dx_cd_b
# Key definitions:
# KEY `dx_cd` (`cd`)
# KEY `dx_cd_b`
(`cd`,`b`),
# Column types:
#
`cd` varchar(50) default null
#
`b` varchar(100) default null
# To remove this duplicate index, execute:
ALTER TABLE `nigel`.`a1` DROP INDEX `dx_cd`;
#
########################################################################
#
nigel.students
#
########################################################################
# dx_n is a left-prefix of dx_n_s
# Key definitions:
# KEY `dx_n` (`name`),
# KEY `dx_n_s`
(`name`,`score`),
# Column types:
#
`name` varchar(25) default null
#
`score` int(5) unsigned not null
# To remove this duplicate index, execute:
ALTER TABLE `nigel`.`students` DROP INDEX `dx_n`;
#
########################################################################
# Summary of
indexes
#
########################################################################
# Size Duplicate Indexes
1348
# Total Duplicate Indexes 2
# Total
Indexes
8
[root@localhost bin]#