我正在尝试设置一个(部分)删除用户的存储过程。我已经尝试了几个“扩展”论点的 DROP USER 版本,但我找不到一个有效的版本。有人可以帮忙吗?
DELIMITER //
CREATE PROCEDURE `dropuser`( IN inUser varchar(255) )
BEGIN
#DROP USER concat(inUser,"@localhost");
#DROP USER inUser "@localhost";
#DROP USER "inUser@localhost";
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");
显然我的扩展有误。
最佳答案
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');
关于mysql - 从存储过程调用 DROP USER,如何扩展输入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7985593/