Home  >  Article  >  Database  >  mysql慢查询日志(slow_query_log_file)切换_MySQL

mysql慢查询日志(slow_query_log_file)切换_MySQL

WBOY
WBOYOriginal
2016-06-01 13:31:47822browse

bitsCN.com

mysql慢查询日志(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小脚本,定义好时间,这样就可以按天生成日志了。

bitsCN.com
Statement:
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