如何在mysql存储过程中授予用户权限?

xdnvmnnf  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(239)

我想在mysql数据库中创建几个存储过程,并使用它们向用户授予特权(类似于角色的实现)。例如,我想让admin1()、admin2()、user\u type1()、user\u 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

这个问题的正确解决方法是什么?我应该如何创建一个用户,将它传递给过程并在那里使用它?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题