Get the App
SLTechnology News&Howtos  ›  Database  › 

How to safely clear the slow query log slowlog online

Shulou Source: shulou.com Published: 2022-05-31 16:01:53 10月03日 Update

This article will explain in detail how to safely empty the slow query log slowlog online. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

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

It is found that the slow query log is more than 2 gigabytes, and it is very slow to use mysqldumpslow statistics. It needs to be emptied and backed up online.

One: close the slow query log

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)

Second: specify a new slow query log file

Mysql > set global slow_query_log_file='/data/DB/mysql/mysql-slow_20160624.log'

Query OK, 0 rows affected (0.00 sec)

Three: open the slow query log

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)

Slow query log file for viewing information

[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

Has started to record slow query logs

Four: back up the old slow query log files

[root@trcloud-gtt-dw backup] # mv / data/DB/mysql/mysql-slow.log / backup/mysql-slow.log.bak.20160624

This is the end of the article on "how to safely empty the slow query log online". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Logs queries online files articles security information backup more good practical content articles time knowledge reference help related statistics Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL MariaDB Xiaomi macOS Microsoft