Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to flush data from mysql.slow_log table in mysql?

Hi i am working on MySQL version 5.5, can somebody please help me to clear/flush data from mysql.slow_log tables in mysql ?

like image 574
Vikrant More Avatar asked Mar 20 '15 09:03

Vikrant More


People also ask

How do you flush a log?

The flush can be done by using the “mysqladmin” for the hosts, logs, status, tables, threads and privileges. To execute the log flushing statements or commands we need to connect to the server with the account which has “RELOAD” Privilege. Flushing the binary log creates a new binary log file.

How do I fix slow queries in MySQL?

Find the execution plan for the query and check whether the query is using appropriate indexes. You can optimize your query using the EXPLAIN plan and review details about how MySQL runs the query. Keep your query statistics updated with the ANALYZE table statement.

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.


3 Answers

You can avoid locking problems without disabling the slow log by using the built-in rotate function:

CALL mysql.rds_rotate_slow_log;
DELETE FROM mysql.slow_log_backup;

This will swap the 'slow_log' and 'slow_log_backup' tables, moving all of the data you want to clear to the non-locked 'slow_log_backup' table, which will happily take the DELETE FROM for data purging purposes.

You can also just invoke rotation twice:

CALL mysql.rds_rotate_slow_log;
CALL mysql.rds_rotate_slow_log;
like image 136
jmsb Avatar answered Oct 14 '22 07:10

jmsb


TRUNCATE mysql.slow_log

From Mysql Documentation:

TRUNCATE TABLE is a valid operation on a log table. It can be used to expire log entries.

like image 34
Renato Liibke Avatar answered Oct 14 '22 05:10

Renato Liibke


If you are on linux

> mysql -uroot -p
> enter your password
> use mysql;
> delete from slow_log;

It will give you an error that you can't lock log tables. Work around is, run the following queries:

SET GLOBAL slow_log= 'OFF';
RENAME TABLE slow_log TO general_log_temp;
DELETE FROM `general_log_temp`;
RENAME TABLE general_log_temp TO slow_log ;
SET GLOBAL slow_log = 'ON';

Taken from "DELETE old rows from Mysql General Log Table"

Update:

You can truncate the table like TRUNCATE mysql.slow_log as mentioned by Renato Liibke

like image 7
Danyal Sandeelo Avatar answered Oct 14 '22 05:10

Danyal Sandeelo