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

自闭症网瘾萝莉.ら 提交于 2019-12-22 06:56:55

问题


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 ?


回答1:


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




回答2:


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;



回答3:


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.




回答4:


For me this works:

SET GLOBAL slow_query_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_query_log = 'ON';


来源:https://stackoverflow.com/questions/29163588/how-to-flush-data-from-mysql-slow-log-table-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!