用脚本:
mysql -N -u root -e "select 'kill ', id,';' from information_schema.processlist WHERE USER NOT IN ('dba','root','rdsadmin')"| mysql -N -u root
用存储过程:
DELIMITER $$
USE `mysql`$$
DROP PROCEDURE IF EXISTS `dba_kill_all`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `dba_kill_all`()
READS SQL DATA
DETERMINISTIC
BEGIN
DECLARE l_user VARCHAR(16);
DECLARE l_id BIGINT;
DECLARE foo VARCHAR(255);
DECLARE l_stopFlag INT;
DECLARE c CURSOR FOR
SELECT id
FROM information_schema.processlist
WHERE USER NOT IN ('dba','root','rdsadmin');
DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_stopFlag=1;
OPEN c;
REPEAT
FETCH c INTO l_id;
KILL l_id;
UNTIL l_stopFlag=1 END REPEAT;
CLOSE c;
END$$
DELIMITER ;
阅读(3781) | 评论(0) | 转发(0) |