percona-toolkit之pt-index-usage和pt-duplicate-key-checker詳解
1>
pt-index-usage:從慢查詢日誌中讀取查詢並分析它們如何使用索引。 (用來查詢不常使用索引)
./pt-index-usage --help
列印報告
./pt-index-usage /mysqldata/mysqlslowlog/slowquery.log -h192.168.226.131 -uroot -p6yhn^YHN -decology
[mysql@mysql bin]$ ./pt-index-usage /mysqldata/mysqlslowlog/slowquery.log -h192.168.226.131 -uroot -p6yhn^YHN
DBD::mysql::db selectall_arrayref failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/' at line 1 [for Statement "EXPLAIN SELECT IFNULL(SUM(INDEX_LENGTH),0) from information_schema.TABLES where ENGINE='InnoDB' */"] at ./pt-index-usage line 4598, <> line 1.
DBD::mysql::db selectall_arrayref failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/' at line 1 [for Statement "EXPLAIN SELECT IFNULL(SUM(DATA_LENGTH),0) from information_schema.TABLES where ENGINE='InnoDB' */"] at ./pt-index-usage line 4598, <> line 2.
DBD::mysql::db selectall_arrayref failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/' at line 1 [for Statement "EXPLAIN SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' */"] at ./pt-index-usage line 4598, <> line 4.
ALTER TABLE `test1`.`user` DROP KEY `idx_1`; -- type:non-unique
2> pt-duplicate-key-checker檢查資料庫的重複索引
索引會更查詢帶來好處,但是過量的索引反而可能會使資料庫的效能降低
./pt-duplicate-key-checker --help
1> 表結構
[root@localhost][test1]> show index from user;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| user | 0 | PRIMARY | 1 | id | A | 1042305 | NULL | NULL | | BTREE | | |
| user | 1 | idx_1 | 1 | id | A | 1042305 | NULL | NULL | | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
欄位id有兩個索引,
[mysql@mysql bin]$ ./pt-duplicate-key-checker -uroot -p6yhn^YHN
# ########################################################################
# test1.user
# ########################################################################
# idx_1 is a duplicate of PRIMARY
# Key definitions:
# KEY `idx_1` (`id`)
# PRIMARY KEY (`id`),
# Column types:
# `id` int(11) not null auto_increment
# To remove this duplicate index, execute:
ALTER TABLE `test1`.`user` DROP INDEX `idx_1`;
# ########################################################################
# Summary of indexes
# ########################################################################
# Size Duplicate Indexes 4169220
# Total Duplicate Indexes 1
# Total Indexes 34
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69950231/viewspace-2665519/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Percona-Toolkit 之 pt-archiverHive
- Percona-Toolkit 之 pt-kill 用法
- Ant詳解之-path、classpath和fileset
- Percona-Toolkit 之 pt-kill 低效SQLSQL
- Percona-toolkit的安裝和配置
- Percona-Toolkit工具包之pt-archiverHive
- netty系列之:NIO和netty詳解Netty
- JavaScript之this詳解JavaScript
- spring之AOP基本概念和配置詳解Spring
- MySQL pt-duplicate-key-checker工具使用初探MySql
- percona-toolkit工具包的安裝和使用
- BeetleX之WebSocket詳解Web
- MySql之EXPLAN詳解MySql
- Flutter之ElevatedButton詳解Flutter
- Java之Super詳解Java
- CSS之Position詳解CSS
- Java 之 synchronized 詳解Javasynchronized
- 網路協議之:socket協議詳解之Socket和Stream Socket協議
- (八)Flutter 和 Native 之間的通訊詳解Flutter
- C語言核心之陣列和指標詳解C語言陣列指標
- Percona-Toolkit 之 pt-archiver 刪除歷史資料Hive
- 機器學習之Xgboost詳解機器學習
- Flutter之DataTable使用詳解Flutter
- 玩轉 JavaScript 之詳解 thisJavaScript
- Ruby Profiler 詳解之 stackprof
- JavaScript之原型深入詳解JavaScript原型
- Flutter 之 Row、Column詳解Flutter
- 【詳解】核心元件之UserDetailService元件AI
- Java之BigDecimal詳解JavaDecimal
- Javascript之字串拼接詳解JavaScript字串
- oracle之 Oracle LOB 詳解Oracle
- Java 之 ThreadLocal 詳解Javathread
- STL 之 vector 容器詳解
- Java 之 volatile 詳解Java
- Python 之 itertools 詳解Python
- iOS之StatusBar詳解iOS
- javaweb之Filter詳解(轉)JavaWebFilter
- Ruby Profiler詳解之stackprof