mysql
常用工具命令集合
-- 查看长时间运行的查询
SELECT id, user, host, db, command, time, state, LEFT(info, 100) as query
FROM information_schema.processlist
WHERE time > 30
AND command != 'Sleep'
ORDER BY time DESC;
-- 杀死长时间运行的查询
KILL QUERY <process_id>;定位cpu占用过高的sql
- 定位线程
# 找出mysql 的进程号
ps -ef | grep mysql
# 根据进程号,找出占用CPU靠前的线程号
top -H -p <mysqld进程id>- 数据库定位sql
SELECT
a.USER,
a.HOST,
a.db,
b.thread_os_id,
b.thread_id,
a.id processlist_id,
a.command,
a.time,
a.state,
a.info
FROM
information_schema.PROCESSLIST a,
performance_schema.threads b
WHERE
a.id = b.processlist_id
AND b.thread_os_id = <具体线程id>;最后更新于