Mysql日志清理

1.3k words

背景

服务器运行一段时间之后,突然报磁盘已满了,查询了一下服务器磁盘后,发现mysql有一个文件占用了快20G

image-20221017101019387

解决方法

  1. 修改慢日志保存路径
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#查询慢日志保存路径
mysql> show variables like '%slow%';
+---------------------------+-----------------------------+
| Variable_name | Value |
+---------------------------+-----------------------------+
| log_slow_admin_statements | OFF |
| log_slow_slave_statements | OFF |
| slow_launch_time | 2 |
| slow_query_log | ON |
| slow_query_log_file | /var/lib/mysql/web-slow.log |
+---------------------------+-----------------------------+
5 rows in set (0.03 sec)

#关闭慢日志
mysql> set global slow_query_log=0;

#设置新保存路径
mysql> set global slow_query_log_file='/var/lib/mysql/web-slow-new.log';

#打开慢日志
mysql> set global slow_query_log=1;

#查询结果
mysql> show variables like '%slow%';
+---------------------------+---------------------------------+
| Variable_name | Value |
+---------------------------+---------------------------------+
| log_slow_admin_statements | OFF |
| log_slow_slave_statements | OFF |
| slow_launch_time | 2 |
| slow_query_log | ON |
| slow_query_log_file | /var/lib/mysql/web-slow-new.log |
+---------------------------+---------------------------------+
5 rows in set (0.04 sec)
  1. 删除原来的慢日志
1
rm /var/lib/mysql/web-slow.log

其他

1
2
#查询正在运行的sql语句
select * from information_schema.`PROCESSLIST` where info is not null;
Comments