我想在我的MySQL数据库中创建几个存储过程,并使用它们向用户授予权限(角色的实现类型)。 例如,我想拥有admin1(),admin2(),user_type1(),user_type2()程序,传递用户名和授予权限。
这是一个函数的例子:
DELIMITER //
CREATE PROCEDURE grant_rights
(IN user varchar(100))
BEGIN
grant update on Table2 to user;
END //
DELIMITER ;
然后我称之为:
mysql> call grant_rights('newuser1');
在此之前,我尝试使用多种方式创建newuser1(带或不带引号):
create user 'newuser1' identified by 'root';
create user newuser1 identified by 'root';
或
create user 'newuser1'@'localhost' identified by 'root';
无论如何,当我授予这样的权利时:
grant update on Table2 to 'newuser1';
一切正常,但在调用程序时(如上图所示),我总是收到错误:
ERROR 1133 (42000): Can't find any matching row in the user table
这个问题的正确解决方案是什么?我应该如何创建用户,将其传递给程序并在那里使用?