p; |
+------------------------------+-----------------------------------------+
| binlog_rows_query_log_events | OFF |
| ft_query_expansion_limit | 20 |
| have_query_cache | YES |
| long_query_time | 0.000000 |
| query_alloc_block_size | 8192 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 16777216 |
| query_cache_type | OFF |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | 8192 |
| slow_query_log | ON |
| slow_query_log_file | /var/lib/mysql/lgj-Lenovo-G470-slow.log |
+------------------------------+-----------------------------------------+
1.3 查询
随便执行一条查询语句,然后查看慢查询日志。
从上面可以获知查询时间和锁表时间,但是如果文件比较大,查找时间最长的查询将会非常麻烦,需要使用相关的工具来进行分析。
2. qt-query-digest的使用
2.1 安装
? 创建目录: mkdir db-analysis && cd db-analysis
? 下载 pt-query-digest: curl -LO https://percona.com/get/pt-query-digest
? 设置执行权限:chmod +x pt-query-digest
? 将慢查询日志的文件复制到当前的目录下
? 执行分析: ./pt-query-digest lgj-Lenovo-G470-slow.log
结果
# 220ms user time, 10ms system time, 33.67M rss, 90.27M vsz
# Current date: Wed Feb 27 22:55:05 2019
# Hostname: lgj-Lenovo-G470
# Files: lgj-Lenovo-G470-slow.log
# Overall: 9 total, 7 unique, 0.24 QPS, 0.00x concurrency ________________
# Time range: 2019-02-27T14:07:29 to 2019-02-27T14:08:07
# Attribute total min max avg 95% stddev median
# ============ ======= ======= ======= ======= ======= ======= ====