MYSQL5.7.9开启慢查询日志的技巧


本文整理自网络,侵删。

用MYSQL 5.7.9 作为ZABBIX 2.4.7 的监控数据库. 前段时间开启了慢查询日志, 后来发现慢查询日志膨胀到了700M

查看最后100条 大部分都是 0.1 秒的 后来想改, 以前是动态设置的 set global slow_query_log=1; 方式的 .

然后想直接用配置文件/etc/my.cnf 配慢查询

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at % of total RAM for dedicated server, else %.
innodb_buffer_pool_size = M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /LANMP/mysql
datadir = /MYSQLDATA/data
port = 
# server_id = .....
socket = /tmp/mysql.sock
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = M
sort_buffer_size = M
read_rnd_buffer_size = M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
character_set_server=utf
init_connect='SET NAMES utf'
slow_query_log = 
slow_query_log_file = /MYSQLDATA/mysql_slow_query.log
long_query_time = 
log_queries_not_using_indexes = ON

反复启动了好多次 service mysqld restart

mysql> show variables like '%query%';
+------------------------------+---------------------------------+
| Variable_name | Value |
+------------------------------+---------------------------------+
| binlog_rows_query_log_events | OFF |
| ft_query_expansion_limit | 20 |
| have_query_cache | YES |
| long_query_time | 5.000000 |
| query_alloc_block_size | 8192 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 1048576 |
| query_cache_type | OFF |
| query_cache_wlock_invalidate | OFF |
| query_prealloc_size | 8192 |
| slow_query_log | ON |
| slow_query_log_file | /MYSQLDATA/mysql_slow_query.log |
+------------------------------+---------------------------------+
13 rows in set (0.00 sec)

老是OFF 状态 而其他的 LONG_QUERY_TIME 得到了改变 5秒

阅读剩余部分

相关阅读 >>

如何查看mysql的日志文件

mysql中如何加密存储

mysql索引更新要多久

mysql怎么清空数据表数据

mysql基本语法

mysql如何导出表的字段和相关属性(附示例)

mysql死锁是什么意思

mysql关闭后自动重启怎么办

mysql 8.0 可以操作 json 了

mysql和navicat什么关系

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...