问题描述
我试图授予用户在 MySQL 数据库上的存储过程级别运行存储过程的权限,而不是允许用户执行数据库中的任何存储过程.我试图执行以下代码:
I am trying to give a user permission to run a stored procedure at the stored procedure level on a MySQL Database rather than allowing a user to execute any stored procedure in the database. I was trying to execute the following code:
GRANT EXECUTE ON myDB.spName TO 'TestUser'@'localhost';
但我不断收到以下错误:非法的 GRANT/REVOKE 命令,请查阅手册以了解可以使用哪些权限.
But i keep getting the following error: Illegal GRANT/REVOKE command, please consult the manual to see which privileges can be used.
我尝试将其更改为以下内容:
I tried changing it to the following:
GRANT EXECUTE ON PROCEDURE myDB.spName TO 'TestUser'@'localhost';
并且我收到一个不同的错误说明:
无法在用户表中找到任何匹配的行.
And i get a different error stating:
Cant find any matching rows in the user table.
我不知道哪里出错了?
同样在 MySQL Workbench 上,我似乎看不到任何通过 GUI 在存储过程级别授予权限的方法.这是正确的还是我遗漏了什么?
Also on the MySQL Workbench I can not seem to see any way to grant permissions at the stored procedure level via the GUI. Is this correct or am I missing something?
提前致谢.
推荐答案
您的第二次尝试是正确的方法:
Your second attempt is the right approach:
GRANT EXECUTE ON PROCEDURE myDB.spName TO 'TestUser'@'localhost';
但如果这不起作用,请验证...
but if that is not working, verify ...
a) 您(您从中运行所有这些命令的用户)拥有授予权限[即具有授予选项].如果您是根用户,那么您就拥有授予权限.
a) you (the user from which you are running all these command) have grant rights [i.e WITH GRANT OPTION]. If you are root, then you have grant rights.
b) 您授予执行权限的用户存在,例如
b) the user exists to which you are granting execute permission e.g.
select user from mysql.user where user like 'test%';
如果没有,则创建用户,例如
If not, then create the user e.g.
CREATE USER 'TestUser'@'localhost' IDENTIFIED BY 'passwordxxxx';
#depending on your needs
GRANT SELECT,DELETE,UPDATE PRIVILEGES ON myDb.* TO 'TestUser'@'localhost';
希望这有帮助:)
这篇关于MySQL 存储过程权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!