这篇文章将为大家详细讲解有关如何在线安全清空慢查询日志slowlog,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
mysql> show variables like '%slow_query%';
+------------------------------------+-------------------------------+
| Variable_name | Value |
+------------------------------------+-------------------------------+
| slow_query_log | ON |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+-------------------------------+
[root@trcloud-gtt-dw backup]# ls -l /data/DB/mysql/mysql-slow.log
-rw-rw---- 1 mysql mysql 2482474901 Jun 24 14:47 /data/DB/mysql/mysql-slow.log
发现慢查询日志已经有2G多了,使用mysqldumpslow统计信息的时候非常慢,需要在线清空并备份
一:关闭慢查询日志
mysql> set global slow_query_log=0;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like '%slow_query%';
+------------------------------------+-------------------------------+
| Variable_name | Value |
+------------------------------------+-------------------------------+
| slow_query_log | OFF |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+-------------------------------+
6 rows in set (0.00 sec)
二:指定新的慢查询日志文件
mysql> set global slow_query_log_file='/data/DB/mysql/mysql-slow_20160624.log';
Query OK, 0 rows affected (0.00 sec)
三:开启慢查询日志
mysql> set global slow_query_log=1;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like '%slow_query%';
+------------------------------------+----------------------------------------+
| Variable_name | Value |
+------------------------------------+----------------------------------------+
| slow_query_log | ON |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_file | /data/DB/mysql/mysql-slow_20160624.log |
| slow_query_log_timestamp_always | OFF |
| slow_query_log_timestamp_precision | second |
| slow_query_log_use_global_control | |
+------------------------------------+----------------------------------------+
6 rows in set (0.00 sec)
查看信息的慢查询日志文件
[root@trcloud-gtt-dw backup]# tail -50f /data/DB/mysql/mysql-slow_20160624.log
# Time: 160624 15:13:28
# User@Host: admin[admin] @ [172.30.250.103] Id: 20178
# Schema: gtt_api Last_errno: 0 Killed: 0
# Query_time: 0.000163 Lock_time: 0.000080 Rows_sent: 1 Rows_examined: 1 Rows_affected: 0
# Bytes_sent: 618
SET timestamp=1466752408;
SELECT invest_money, total_earning, invest_this_month, invest_last_month, total_wait_earning, total_people FROM th_home_data;
已经开始记录慢查询日志
四:备份老的慢查询日志文件
[root@trcloud-gtt-dw backup]# mv /data/DB/mysql/mysql-slow.log /backup/mysql-slow.log.bak.20160624
关于“如何在线安全清空慢查询日志slowlog”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。