查看tidb的slow sql,两种方式:
1、直接查看tidb_slow_query.log的日志文件
#查找日志文件路径 MySQL [rkw_ezc_test]> show variables like 'tidb_slow_query_file'; +----------------------+---------------------------------------+ | Variable_name | Value | +----------------------+---------------------------------------+ | tidb_slow_query_file | /data1/deploy/log/tidb_slow_query.log | +----------------------+---------------------------------------+ 1 row in set (0.00 sec) #找到tidb节点,查看/data1/deploy/log/tidb_slow_query.log日志文件 [root@tidb-23 ~]# more /data1/deploy/log/tidb_slow_query.log # Time: 2020-07-11T02:02:56.386999054+08:00 # Txn_start_ts: 417963488275333123 # Query_time: 0.523451656 # Backoff_time: 0.52 Request_count: 2 # Index_ids: [1] # Is_internal: true # Digest: ab6d79d3e75abdf0ba1e0fb7161312e07099349d4d14a13968fa9cc7767d66a1 # Stats: tidb:pseudo # Num_cop_tasks: 2 # Cop_proc_avg: 0 Cop_proc_p90: 0 Cop_proc_max: 0 Cop_proc_addr: 172.21.210.25:20160 # Cop_wait_avg: 0 Cop_wait_p90: 0 Cop_wait_max: 0 Cop_wait_addr: 172.21.210.25:20160 # Mem_max: 9596
2、直接数据库查看数据库的slow表
#直接数据库查询表 MySQL [rkw_ezc_test]> select `Query_time`, query from INFORMATION_SCHEMA.`SLOW_QUERY` where `Is_internal`=false order by `Query_time` desc limit 10; #将慢查询sql结果导出到文件; mysqldump -h 172.21.210.23 -P 4000 -u root -p -e “admin show slow top 10” >slow.sql