当前位置:Gxlcms > mysql > mysql正确安全清空在线慢查询日志slowlog的流程分享

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

时间:2021-07-01 10:21:17 帮助过:18人阅读

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

您可能感兴趣的文章:

  • 详解MySql的慢查询分析及开启慢查询日志
  • mysql 开启慢查询 如何打开mysql的慢查询日志记录
  • MYSQL5.7.9开启慢查询日志的技巧
  • MySQL开启慢查询日志log-slow-queries的方法
  • MySQL慢查询优化之慢查询日志分析的实例教程
  • MySQL 开启慢查询日志的方法
  • 对MySQL慢查询日志进行分析的基本教程
  • 根据mysql慢日志监控SQL语句执行效率
  • MySQL中查询日志与慢查询日志的基本学习教程
  • MySQL慢查日志的开启方式与存储格式详析

人气教程排行