Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to safely clear the slow query log slowlog online

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report