Home > Database > Mysql Tutorial > body text

MySQL 慢查询日志(slow_query_log_file)切换

WBOY
Release: 2016-06-07 17:30:45
Original
948 people have browsed it

slow_query_log_file日志变得很大,对它进项分析变得很不方便,我们就想按天每天产生一个slow_query_log_file文件,每天分析这个

slow_query_log_file日志变得很大,对它进项分析变得很不方便,我们就想按天每天产生一个slow_query_log_file文件,每天分析这个日志文件。如何按天切割呢?我们想到了这么一个办法,把日志格式切换成这种形式的hostname-slow_日期.log 这种形式,,默认格式为hostname-slow.log。那么如何实现呢?其实很简单。利用mysql默认命令就可以了

mysql> show variables like '%query%log%';
+---------------------+----------------------------------------+
| Variable_name | Value |
+---------------------+----------------------------------------+
| slow_query_log | OFF |
| slow_query_log_file | /usr/local/mysql/data/aeolus1-slow.log |
+---------------------+----------------------------------------+

mysql> set global slow_query_log_file='/usr/local/mysql/data/aeolus1-slow_2013-07-19.log' ;
Query OK, 0 rows affected (0.03 sec)

mysql> show variables like '%query%log%';
+---------------------+---------------------------------------------------+
| Variable_name | Value |
+---------------------+---------------------------------------------------+
| slow_query_log | ON |
| slow_query_log_file | /usr/local/mysql/data/aeolus1-slow_2013-07-19.log |
+---------------------+---------------------------------------------------+
2 rows in set (0.01 sec)

ok,设置成功。思路就是这样的

写个shell小脚本,定义好时间,这样就可以按天生成日志了。

相关阅读:

MySQL慢查询开启及分析方法

分析MySQL慢查询日志的好工具--mysqlsla

MySQL前缀索引导致的慢查询

【体系结构】MySQL 日志文件--慢查询日志

MySQL调优三步曲(慢查询、explain profile)

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!