DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`slowLog_prune`() BEGIN /** * Prunes MySQL slow query log table deleting all records older than one week. */ DECLARE vSlowQueryLog INT DEFAULT @@slow_query_log; DECLARE vSqlLogBin INT DEFAULT @@SESSION.sql_log_bin; SET sql_log_bin = OFF; SET GLOBAL slow_query_log = OFF; RENAME TABLE `mysql`.`slow_log` TO `mysql`.`slow_log_temp`; DELETE FROM `mysql`.`slow_log_temp` WHERE start_time < TIMESTAMPADD(WEEK, -1, util.VN_NOW()); RENAME TABLE `mysql`.`slow_log_temp` TO `mysql`.`slow_log`; SET GLOBAL slow_query_log = vSlowQueryLog; SET sql_log_bin = vSqlLogBin; END$$ DELIMITER ;