DELIMITER $$

USE `mysql`$$

DROP PROCEDURE IF EXISTS `rds_rotate_slow_log`$$

CREATE DEFINER=`rdsadmin`@`localhost` PROCEDURE `rds_rotate_slow_log`()
    READS SQL DATA
    DETERMINISTIC
BEGIN
  DECLARE sql_logging BOOLEAN;
  SELECT @@sql_log_bin INTO sql_logging;
  SET @@sql_log_bin=off;
  CREATE TABLE IF NOT EXISTS mysql.slow_log_template LIKE mysql.slow_log;
  CREATE TABLE IF NOT EXISTS mysql.slow_log2 LIKE mysql.slow_log_template;
  DROP TABLE IF EXISTS mysql.slow_log_backup;
  RENAME TABLE mysql.slow_log TO mysql.slow_log_backup, mysql.slow_log2 TO mysql.slow_log;
  SET @@sql_log_bin=sql_logging;
END$$

DELIMITER ;

DELIMITER $$

USE `mysql`$$

DROP PROCEDURE IF EXISTS `rds_rotate_general_log`$$

CREATE DEFINER=`rdsadmin`@`localhost` PROCEDURE `rds_rotate_general_log`()
    READS SQL DATA
    DETERMINISTIC
BEGIN
  DECLARE sql_logging BOOLEAN;
  SELECT @@sql_log_bin INTO sql_logging;
  SET @@sql_log_bin=off;
  CREATE TABLE IF NOT EXISTS mysql.general_log_template LIKE mysql.general_log;
  CREATE TABLE IF NOT EXISTS mysql.general_log2 LIKE mysql.general_log_template;
  DROP TABLE IF EXISTS mysql.general_log_backup;
  RENAME TABLE mysql.general_log TO mysql.general_log_backup, mysql.general_log2 TO mysql.general_log;
  SET @@sql_log_bin=sql_logging;
END$$

DELIMITER ;

DELIMITER $$

USE `mysql`$$

DROP PROCEDURE IF EXISTS `rds_set_fk_checks_on`$$

CREATE DEFINER=`rdsadmin`@`localhost` PROCEDURE `rds_set_fk_checks_on`()
BEGIN
DECLARE v_called_by_user VARCHAR(50);
DECLARE v_mysql_version VARCHAR(20);
DECLARE sql_logging BOOLEAN;
SELECT @@sql_log_bin INTO sql_logging;
SELECT USER() INTO v_called_by_user;
SELECT VERSION() INTO v_mysql_version;
SET @@sql_log_bin=off;
INSERT INTO mysql.rds_history(called_by_user, ACTION, mysql_version) VALUES (v_called_by_user,'set_fk_checks_on', v_mysql_version);
COMMIT;
SET GLOBAL `foreign_key_checks`=1;
SET @@sql_log_bin=sql_logging;
END$$

DELIMITER ;
12-14 09:31