Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Truncate Slow Query Log in MySQL

What's the safest way to truncate the MySQL slow query log (under Linux primarily, but Windows would be handy to know) while MySQL is running?

By safe I mean:

  • Mustn't cause any permissions problems
  • Mustn't jump back to its original size next time its appended to
like image 438
Greg Avatar asked Feb 23 '09 11:02

Greg


People also ask

How do I fix slow queries in MySQL?

The following is the best process for collecting and aggregating the top queries: Set long_query_time = 0 (in some cases, you may need to rate limit to not flood the log) Enable the slow log and collect for some time (slow_query_log = 1) Stop collection and process the log with pt-query-digest.

How do I disable slow query log in MySQL?

To disable or enable the slow query log or change the log file name at runtime, use the global slow_query_log and slow_query_log_file system variables. Set slow_query_log to 0 to disable the log or to 1 to enable it.

What is MySQL slow log?

The MySQL slow query log is where the MySQL database server registers all queries that exceed a given threshold of execution time. This can often be a good starting place to see which queries are slowest and how often they are slow. MySQL on your server is configured to log all queries taking longer than 0.1 seconds.

How do I find the slow query log path in MySQL?

By default, the slow query log file is located at /var/lib/mysql/hostname-slow. log. We can also set up another location as shown in listing 03 using the slow_query_log_file parameter.


1 Answers

To truncate a file regardless if it is open by a running application do:

> /var/logs/your.log

at your shell prompt.

like image 54
vartec Avatar answered Oct 20 '22 12:10

vartec