2011-11-02 3 views
1

부분적으로 사용자를 삭제하는 저장 프로 시저를 설정하려고합니다. 인수를 "확장"하는 DROP USER의 여러 버전을 시도했지만 작동하는 하나를 찾을 수 없습니다. 누군가 도울 수 있습니까?저장된 프로 시저에서 DROP USER 호출, 입력 인수를 확장하는 방법

DELIMITER // 
CREATE PROCEDURE `dropuser`(IN inUser varchar(255)) 
BEGIN 
    #DROP USER concat(inUser,"@localhost"); 
    #DROP USER inUser "@localhost"; 
    #DROP USER "[email protected]"; 
END// 
DELIMITER ; 

CALL dropuser("asdf"); 

그들 중 세 명 모두 같은 방법으로 실패 :

ERROR 1064 (42000) at line 4: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(inUser,"@localhost"); 

은 분명히 내가 확장 잘못을 얻고있다.

답변

0
delimiter // 
drop procedure if exists dropuser // 
create procedure dropuser(in inUser varchar(255)) 
begin 
    set @str = concat('drop user ', "'",inUser,"'@","'localhost'"); 
    prepare stmt from @str; 
    -- select @str; 
    execute stmt; 
    deallocate prepare stmt; 
end// 
delimiter ; 

call dropuser('pippo'); 
+0

완벽! 또한 'GRANT .. IDENTIFIED BY'를 사용하여이 작업을 수행하지 않아도됩니다. – tedder42

+0

기꺼이 도와 드리겠습니다. :) –

관련 문제