码迷,mamicode.com
首页 > 数据库 > 详细

MySQL慢查询日志分割

时间:2014-09-15 15:33:39      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:ar   2014   div   sp   cti   log   on   c   sql   

mysql> set global slow_query_log=0;
Query OK, 0 rows affected (0.00 sec)
 
mysql> set global slow_query_log_file=‘/data/mysql_33096/mysqllog/slow_query_2014-06-09.log‘;
Query OK, 0 rows affected (0.00 sec)
 
mysql> show variables like ‘slow%‘;
+---------------------+------------------------------------------------------+
| Variable_name | Value |
+---------------------+------------------------------------------------------+
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | /data/mysql_33096/mysqllog/slow_query_2014-06-09.log |
+---------------------+------------------------------------------------------+
 
mysql> set global slow_query_log=1;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like ‘slow%‘;
+---------------------+-------------------------------------------+
| Variable_name | Value |
+---------------------+-------------------------------------------+
| slow_launch_time | 2 |
| slow_query_log | ON |
| slow_query_log_file | /data/mysql_33096/mysqllog/slow_query.log |
+---------------------+-------------------------------------------+
3 rows in set (0.00 sec)
 

/root/slowlog.sh脚本
 
#!/bin/bash
####split mysql slow-query-log#######
LOGDIR=/data/mysqllog
DATE=`date +"%Y-%m-%d"`
user=xxx
passwd=****
#stop slow_query_log
mysql -u$user -p$passwd -e "set global slow_query_log=0"
#reset the filename of slow_query_log
mysql -u$user -p$passwd -e "set global slow_query_log_file=‘${LOGDIR}/slow_query_${DATE}.log‘"
#enable slow_query_log
mysql -u$user -p$passwd -e "set global slow_query_log=1"
#remove slow_query_log 7days ago.
cd $LOGDIR
find ./slow_query* -ctime +7 -exec rm -f {} \;

定时任务:
 
[wy@dev88 home]$ sudo crontab -e
00 0 * * * /root/slowlog.sh

MySQL慢查询日志分割

标签:ar   2014   div   sp   cti   log   on   c   sql   

原文地址:http://www.cnblogs.com/rockbes/p/3972749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!