Skip to content

常用

工具 https://github.com/percona/percona-toolkit

创建聚合索引

create index idx_all on tb_1(filed_1, filed_2);

查看正在执行的语句,并删除

# 查看
show processlist;

show full processlist;

# 根据状态查找,也可根据info查找info是执行的sql语句
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND != 'Sleep';

# 删除
kill query 60581562;

分析

主要就是看type字段。

EXPLAIN sql;

查看没有建立索引的表

SELECT 
    table_schema AS `Database`,
    table_name AS `Table`
FROM 
    information_schema.tables
WHERE 
    table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys') -- 排除系统数据库
    AND table_type = 'BASE TABLE'
    AND NOT EXISTS (
        SELECT 
            1
        FROM 
            information_schema.statistics
        WHERE 
            table_schema = tables.table_schema
            AND table_name = tables.table_name
        LIMIT 1
    )
ORDER BY 
    table_schema, table_name;