MySQL slow query log

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

The MySQL slow query log enables you to log all queries that take longer than a specified number of seconds to execute.  This should help identify any queries that are not performing sufficiently.

All that is required is two additional lines in the MySQL configuration file “my.cnf” in the [mysqld] section.

[mysqld]
log-slow-queries = /var/log/mysql-slow.log
long_query_time = 4
 

The above configuration will log any queries taking longer than 4 seconds to execute in to the specified log file.

MySQL appears to require that the specified log file exists otherwise the logging is disabled and the error below

appears in the MySQL log. (Or it may be that it didn’t have permissions to create the file. I haven’t investigated).

081013 14:55:37 [ERROR] Could not use /var/log/mysql-slow.log for logging (error 13). Turning logging off for
the whole duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server
and restart it.

To create the log file I did the following:

touch /var/log/mysql-slow.log
chown mysql.mysql /var/log/mysql-slow.log
chmod o-r /var/log/mysql-slow.log

The third command is probably unnecessary, but it meant that the permissions matched the mysqld.log

in the same directory.

Once this is done MySQL needs to be restarted to start the query logging:

service mysql restart
 

This entry was posted on Monday, October 13th, 2008 at 5:34 pm and is filed under MySQL. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

 


本文转自holy2009 51CTO博客,原文链接:http://blog.51cto.com/holy2010/362340


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
7天前
|
关系型数据库 MySQL 数据管理
MySQL通过 bin-log 恢复从备份点到灾难点之间数据
MySQL通过 bin-log 恢复从备份点到灾难点之间数据
|
14天前
|
DataWorks 关系型数据库 MySQL
DataWorks产品使用合集之在DataWorks中,如何通过PolarDB for MySQL来查看binlog日志
DataWorks作为一站式的数据开发与治理平台,提供了从数据采集、清洗、开发、调度、服务化、质量监控到安全管理的全套解决方案,帮助企业构建高效、规范、安全的大数据处理体系。以下是对DataWorks产品使用合集的概述,涵盖数据处理的各个环节。
28 1
|
14天前
|
SQL 监控 关系型数据库
【MySQL学习】MySQL的慢查询日志和错误日志
【MySQL学习】MySQL的慢查询日志和错误日志
|
20天前
|
SQL 存储 关系型数据库
MySQL慢日志的介绍以及如何使用问题
MySQL慢日志的介绍以及如何使用问题
19 0
|
1月前
|
安全 Linux 网络安全
/var/log/secure日志详解
Linux系统的 `/var/log/secure` 文件记录安全相关消息,包括身份验证和授权尝试。它涵盖用户登录(成功或失败)、`sudo` 使用、账户锁定解锁及其他安全事件和PAM错误。例如,SSH登录成功会显示"Accepted password",失败则显示"Failed password"。查看此文件可使用 `tail -f /var/log/secure`,但通常只有root用户有权访问。
121 4
|
7天前
|
C++
JNI Log 日志输出
JNI Log 日志输出
15 1
|
7天前
|
存储 运维 大数据
聊聊日志硬扫描,阿里 Log Scan 的设计与实践
泛日志(Log/Trace/Metric)是大数据的重要组成,伴随着每一年业务峰值的新脉冲,日志数据量在快速增长。同时,业务数字化运营、软件可观测性等浪潮又在对日志的存储、计算提出更高的要求。
|
13天前
|
XML Java Maven
Springboot整合与使用log4j2日志框架【详解版】
该文介绍了如何在Spring Boot中切换默认的LogBack日志系统至Log4j2。首先,需要在Maven依赖中排除`spring-boot-starter-logging`并引入`spring-boot-starter-log4j2`。其次,创建`log4j2-spring.xml`配置文件放在`src/main/resources`下,配置包括控制台和文件的日志输出、日志格式和文件切分策略。此外,可通过在不同环境的`application.yml`中指定不同的log4j2配置文件。最后,文章提到通过示例代码解释了日志格式中的各种占位符含义。
|
13天前
|
运维 监控 Go
Golang深入浅出之-Go语言中的日志记录:log与logrus库
【4月更文挑战第27天】本文比较了Go语言中标准库`log`与第三方库`logrus`的日志功能。`log`简单但不支持日志级别配置和多样化格式,而`logrus`提供更丰富的功能,如日志级别控制、自定义格式和钩子。文章指出了使用`logrus`时可能遇到的问题,如全局logger滥用、日志级别设置不当和过度依赖字段,并给出了避免错误的建议,强调理解日志级别、合理利用结构化日志、模块化日志管理和定期审查日志配置的重要性。通过这些实践,开发者能提高应用监控和故障排查能力。
88 1
|
15天前
|
弹性计算 运维 Shell