Leif160519的blog Leif160519的blog

——————

目录
MySQL慢查询日志配置
/  

MySQL慢查询日志配置

查看慢查询配置文件

mysql> show variables like 'slow_query_log';
+----------------+-------+
| Variable_name  | Value |
+----------------+-------+
| slow_query_log | OFF   |
+----------------+-------+
1 row in set (0.00 sec)

开启慢查询日志

mysql>set global slow_query_log = on;

查看:

mysql> show variables like 'slow_query_log';
+----------------+-------+
| Variable_name  | Value |
+----------------+-------+
| slow_query_log | ON    |
+----------------+-------+
1 row in set (0.03 sec)

设置日志文件路径

mysql> set global slow_query_log_file = '/var/log/mysql/mysql-slow.log';
Query OK, 0 rows affected (0.04 sec)

若mysql采用的docker集群方式,则log文件在容器中

若mysql是单节点物理机中安装的,记得/var/log下的mysql文件夹要赋予mysql属组,否则不会生成mysql-slow.log文件

chown mysql:mysql /var/log/mysql/

记录没用使用索引查找的SQL

mysql>set global log_queries_not_using_indexes = on; 

记录插叙语句超过一定时间的SQL (秒)

mysql>set global long_query_time  = 0.1; 

查看:

mysql> show variables like '%quer%';
+----------------------------------------+-------------------------------+
| Variable_name                          | Value                         |
+----------------------------------------+-------------------------------+
| binlog_rows_query_log_events           | OFF                           |
| ft_query_expansion_limit               | 20                            |
| ft_query_extra_word_chars              | OFF                           |
| have_query_cache                       | YES                           |
| log_queries_not_using_indexes          | ON                            |
| log_throttle_queries_not_using_indexes | 0                             |
| long_query_time                        | 10.000000                     |
| query_alloc_block_size                 | 8192                          |
| query_cache_limit                      | 1048576                       |
| query_cache_min_res_unit               | 4096                          |
| query_cache_size                       | 16777216                      |
| query_cache_strip_comments             | OFF                           |
| query_cache_type                       | OFF                           |
| query_cache_wlock_invalidate           | OFF                           |
| query_prealloc_size                    | 8192                          |
| slow_query_log                         | ON                            |
| slow_query_log_always_write_time       | 10.000000                     |
| slow_query_log_file                    | /var/log/mysql/mysql-slow.log |
| slow_query_log_use_global_control      |                               |
| wsrep_reject_queries                   | NONE                          |
| wsrep_sst_donor_rejects_queries        | OFF                           |
+----------------------------------------+-------------------------------+
21 rows in set (0.04 sec)

参考:
https://blog.csdn.net/qq_33652147/article/details/85787812
https://www.cnblogs.com/jiqing9006/p/9098181.html


“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill

标  题MySQL慢查询日志配置
作  者Leif160519
出  处https://github.icu/articles/2019/09/24/1569328362230.html
关于博主:坐标六朝古都南京,服务器运维工程师+桌面运维工程师,如有问题探讨可以直接下方留言。
声援博主:如果您觉得文章对您有帮助,可以评论、订阅、收藏。您的鼓励是博主的最大动力!