FYI, this is the best solution ... !!!
The following SP will help you remove the user 'tempuser'@'%' by executing CALL DropUserIfExistsAdvanced('tempuser', '%');
If you want to delete all users named 'tempuser' (say 'tempuser'@'%' , 'tempuser'@'localhost' and 'tempuser'@'192.168.1.101' ), execute SP as CALL DropUserIfExistsAdvanced('tempuser', NULL); This will delete all users named tempuser !!! Really...
Now, please look at the mentioned DropUserIfExistsAdvanced SP:
DELIMITER $$ DROP PROCEDURE IF EXISTS `DropUserIfExistsAdvanced`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `DropUserIfExistsAdvanced`( MyUserName VARCHAR(100) , MyHostName VARCHAR(100) ) BEGIN DECLARE pDone INT DEFAULT 0; DECLARE mUser VARCHAR(100); DECLARE mHost VARCHAR(100); DECLARE recUserCursor CURSOR FOR SELECT `User`, `Host` FROM `mysql`.`user` WHERE `User` = MyUserName; DECLARE CONTINUE HANDLER FOR NOT FOUND SET pDone = 1; IF (MyHostName IS NOT NULL) THEN
Application:
CALL DropUserIfExistsAdvanced('tempuser', '%'); to remove user 'tempuser'@'%'
CALL DropUserIfExistsAdvanced('tempuser', '192.168.1.101'); to delete the user 'tempuser'@'192.168.1.101'
CALL DropUserIfExistsAdvanced('tempuser', NULL); delete all users with the name 'tempuser' (for example, 'tempuser'@'%' , 'tempuser'@'localhost' and 'tempuser'@'192.168.1.101' )
rajukoyilandy Sep 19 '12 at 20:08 2012-09-19 20:08
source share