2013-04-20 198 views
4

我正在將我的腳趾浸入使用MySQL存儲的函數中,並遇到了麻煩。無法執行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上!)。

謝謝

回答

4

test2.foo是一個函數而不是過程。

嘗試:

GRANT EXECUTE ON FUNCTION test2.foo TO 'tester'@'localhost'; 

(我是能夠在本地重現該問題,並確認這種變化的作品。)

+0

感謝肖恩。我知道我錯過了一些非常明顯的事情:-)。 – nurdglaw 2013-04-21 08:03:09