【发布时间】:2013-04-20 23:34:58
【问题描述】:
我正在尝试在 MySQL 中使用存储函数,但遇到了麻烦。
创建了一个函数并对其进行了测试,我似乎无法让其他用户执行它。从文档来看,我似乎需要向其他用户授予 EXECUTE 访问权限,但这似乎还不够。
我已经整理了几个我认为可以证明问题的脚本:
# This script creates two databases with a stored function in each.
#
# On one database, tester in granted all privileges.
# On the other, tester only gets a few.
#
# We want to find the minimum privileges required to allow tester to execute the
# stored function.
#
# This script must be run by an administrative user, i.e. root
CREATE DATABASE test1;
DELIMITER $$
CREATE FUNCTION test1.foo () RETURNS VARCHAR(255) DETERMINISTIC
BEGIN
RETURN ('garp');
END$$
DELIMITER ;
GRANT ALL PRIVILEGES ON test1.* TO 'tester'@'localhost';
#
CREATE DATABASE test2;
DELIMITER $$
CREATE FUNCTION test2.foo () RETURNS VARCHAR(255) DETERMINISTIC
BEGIN
RETURN ('garp');
END$$
DELIMITER ;
GRANT EXECUTE ON PROCEDURE test2.foo TO 'tester'@'localhost';
和
# This script tests whether tester can access the stored functions
#
# It should be executed by tester
SELECT 'test1.foo(): ', test1.foo ();
SELECT 'test2.foo(): ', test2.foo ();
当我运行执行第二个脚本时,我得到一个错误:
$ mysql --user=tester --password=tester --skip-column-names < testScript2.sql
test1.foo(): garp
ERROR 1370 (42000) at line 6: execute command denied to user 'tester'@'localhost' for routine 'test2.foo'
我毫不怀疑我遗漏了一些明显的东西,但我看不出那是什么。我想我在第一个脚本中的 GRANT EXECUTE... 语句中有问题,并且对我对单引号的使用深表怀疑,但我记得尝试了大多数放置和包含单引号的组合但没有成功。
非常感谢任何能指出我的错误的人。
作为参考,我正在运行 Server version: 5.1.67-0ubuntu0.10.04.1 (Ubuntu)(在 Ubuntu 上!)。
谢谢
【问题讨论】: