欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql正确安全清空在线慢查询日志slow log的流程分享

程序员文章站 2024-02-26 16:40:52
1, see the slow log status; mysql> show variables like '%slow%';+-----------------...

1, see the slow log status;

mysql> show variables like '%slow%';
+---------------------+------------------------------------------+
| variable_name       | value                                    |
+---------------------+------------------------------------------+
| log_slow_queries    | on                                       |
| slow_launch_time    | 2                                        |
| slow_query_log      | on                                       |
| slow_query_log_file | /mysqllog/slow_log/slow_queries_3306.log |
+---------------------+------------------------------------------+
4 rows in set (0.00 sec)

2, stop the slow log server.

mysql> set global slow_query_log=0;
query ok, 0 rows affected (0.27 sec)

mysql> show variables like '%slow%';
+---------------------+------------------------------------------+
| variable_name       | value                                    |
+---------------------+------------------------------------------+
| log_slow_queries    | off                                      |
| slow_launch_time    | 2                                        |
| slow_query_log      | off                                      |
| slow_query_log_file | /mysqllog/slow_log/slow_queries_3306.log |
+---------------------+------------------------------------------+
4 rows in set (0.00 sec)

mysql>
mysql> show variables like '%slow%'; -- check slow log status
+---------------------+------------------------------------------+
| variable_name       | value                                    |
+---------------------+------------------------------------------+
| log_slow_queries    | off                                      |
| slow_launch_time    | 2                                        |
| slow_query_log      | off                                      |
| slow_query_log_file | /mysqllog/slow_log/slow_queries_3306.log |
+---------------------+------------------------------------------+
4 rows in set (0.00 sec)

3, reset the new path of slow log

mysql> set global slow_query_log_file='/mysqllog/slow_log/slow_queries_3306_new.log';
query ok, 0 rows affected (0.03 sec)

4, start the slow log server

mysql>
mysql>
mysql> set global slow_query_log=1;
query ok, 0 rows affected (0.01 sec)


mysql> show variables like '%slow%';
+---------------------+----------------------------------------------+
| variable_name       | value                                        |
+---------------------+----------------------------------------------+
| log_slow_queries    | on                                           |
| slow_launch_time    | 2                                            |
| slow_query_log      | on                                           |
| slow_query_log_file | /mysqllog/slow_log/slow_queries_3306_new.log |
+---------------------+----------------------------------------------+
4 rows in set (0.00 sec)

5, check the slow sql in the new slow log file.

mysql> select sleep(10) as a, 1 as b;
+---+---+
| a | b |
+---+---+
| 0 | 1 |
+---+---+
1 row in set (10.00 sec)

mysql>
[mysql@xxx-xxx ~]$ more /mysqllog/slow_log/slow_queries_3306_new.log
......
time                 id command    argument
# time: 140213  6:44:24
# user@host: root[root] @ localhost []
# query_time: 10.000365  lock_time: 0.000000 rows_sent: 1  rows_examined: 0
set timestamp=1392273864;
select sleep(10) as a, 1 as b;

6, backup the old big slow log file to other directory.

mv /mysqllog/slow_log/slow_queries_3306.log /mysqlbackup/slow_log/slow_queries_3306.log.bak.20140213