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

时间:2024-01-24 12:25:48 

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,slow,log
0
投稿

猜你喜欢

  • 使用 Python 破解压缩文件的密码的思路详解

    2021-09-29 22:36:48
  • Python 实现静态链表案例详解

    2022-08-31 01:56:48
  • Python通用验证码识别OCR库之ddddocr验证码识别

    2021-05-16 22:55:00
  • 对python 匹配字符串开头和结尾的方法详解

    2023-02-03 23:45:40
  • python requests包的request()函数中的参数-params和data的区别介绍

    2021-05-04 18:21:13
  • python在控制台输出进度条的方法

    2022-01-12 09:27:15
  • Mysql运行环境优化(Linux系统)

    2024-01-14 16:38:03
  • MySQL Dump/Restore

    2010-10-14 13:49:00
  • 浅谈flask源码之请求过程

    2023-12-17 10:36:48
  • Python tempfile模块生成临时文件和临时目录

    2022-06-28 05:20:20
  • 漫谈前端开发中的团队合作

    2009-02-05 21:02:00
  • JavaScript 解析 Cookie 的函数

    2007-11-08 11:58:00
  • 如何修改MySQL密码(方法大总结)

    2009-11-18 11:07:00
  • Python创建文件和追加文件内容实例

    2021-03-15 04:38:09
  • Git配置用户签名方式的拓展示例实现全面讲解

    2023-03-12 14:46:59
  • OpenCV学习方框滤波实现图像处理代码示例

    2023-02-08 17:17:43
  • 获取select的value、text值的简单示例(jquery与javascript)

    2024-04-22 12:49:51
  • 详解MySQL中的事务与ACID特性

    2024-01-14 21:59:38
  • JavaScript函数的调用以及参数传递

    2024-04-18 10:32:30
  • 使用torchtext导入NLP数据集的操作

    2023-08-19 16:07:10
  • asp之家 网络编程 m.aspxhome.com