[英]Create stored procedure with specific schema in MYSQL and grant execute permission to user
Hello i have two db schemas " results " and " base ".您好,我有两个数据库模式“结果”和“基础”。 I am trying to create stored procedure in "results" database, and at the same time to give permission to user to run this procedure.
我正在尝试在“结果”数据库中创建存储过程,同时授予用户运行此过程的权限。 What i did is:
我所做的是:
DELIMITER //
DROP PROCEDURE IF EXISTS results.truncateResultsTable //
CREATE PROCEDURE results.truncateResultsTable(genId VARCHAR(255))
BEGIN
SET @genId = genId;
SET @q = CONCAT('TRUNCATE TABLE results_' , @genId);
PREPARE stmt FROM @q;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
GRANT EXECUTE ON FUNCTION results.truncateResultsTable TO 'lam_api'@'%';
END //
But getting this error但是得到这个错误
execute command denied to user 'lam_api'@'%' for routine 'results.truncateResultsTable
Any idea what i am doing wrong?知道我在做什么错吗?
Here is right solution, i had couple of issues.这是正确的解决方案,我有几个问题。 GARANT part was misplaced, also was missing DELIMITER ;
GARANT部分放错了位置,也缺少DELIMITER ;
DELIMITER //
DROP PROCEDURE IF EXISTS results.truncateResultsTable //
CREATE PROCEDURE results.truncateResultsTable(genId VARCHAR(255))
BEGIN
SET @genId = genId;
SET @q = CONCAT('TRUNCATE TABLE results_' , @genId);
PREPARE stmt FROM @q;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END //
DELIMITER ;
GRANT EXECUTE ON PROCEDURE results.truncateResultsTable TO 'lam_api'@'%';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.