Grant Execute Function permission to another user
You have to use grant execute on the function
(Approach 2):
GRANT EXECUTE ON FUNCTION `db_name`.`fn_relation_isModerator` TO 'api_workers'@'%';
As explained in the comments by OP, there was a typo in user, it should be api_workers
instead of api_worker
.
All approaches failed due to the use of non-existent user.
![Shaharyar](https://i.stack.imgur.com/ZcpU1.jpg?s=256&g=1)
Shaharyar
Recipe For Handling Rapid Growth while (true) { identify_and_fix_bottlenecks(); eat(); sleep(); notice_new_bottleneck(); } Contact: [email protected]
Updated on June 26, 2022Comments
-
Shaharyar about 2 years
I have a database function
fn_relation_isModerator
, only userapi
has access to this function. Now I want another user to have this permission (while keeping the previous permission as well).I checked routine name and user by following query:
select routine_name, routine_type, definer from information_schema.ROUTINES where ROUTINE_SCHEMA = 'db_name';
Which resulted:
+-------------------------+---------------+----------+ | ROUTINE_NAME | ROUTINE_TYPE | DEFINER | +-------------------------+---------------+----------+ | | | | | fn_relation_isModerator | FUNCTION | api@% | +-------------------------+---------------+----------+
Approach 1:
So I ran the following query to grant this permission:
GRANT EXECUTE ON PROCEDURE db_name.fn_relation_isModerator TO 'api_worker'@'%';
But it resulted in following error:
Error Code: 1305. PROCEDURE fn_relation_isModerator does not exist
Approach 2:
Query:
GRANT EXECUTE ON FUNCTION `db_name`.`fn_relation_isModerator` TO 'api_worker'@'%';
Error
Error Code: 1133. Can't find any matching row in the user table
Approach 3:
Query:
GRANT EXECUTE ON `db_name`.`fn_relation_isModerator` TO 'api_worker'@'%';
Error:
Error Code: 1144. Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used
-
Michael about 6 yearsAre you trying to do it as root?
-
Shaharyar about 6 years@MichaelO. Yes!
-
Michael about 6 yearsYour second approach is correct. Maybe try creating the user?
-
Shaharyar about 6 yearsIt already exists
-
-
Shaharyar about 6 yearsI already tried it, mentioned in Approach 2. Resulted with error
Error Code: 1133. Can't find any matching row in the user table
-
revo about 6 yearsSorry I think I missed it. Then it means
api_worker
user on%
host doesn't exist yet. Do aSELECT CONCAT(User, '@', Host) FROM mysql.user;
to confirm. -
revo about 6 yearsDid you run that select query?
-
Shaharyar about 6 yearsWhich query? Sorry didn't get your reference?
-
revo about 6 yearsNo problem:
SELECT CONCAT(User, '@', Host) FROM mysql.user;
-
Shaharyar about 6 yearsYes, here are the results image.ibb.co/cAx4v8/Screenshot_from_2018_06_10_01_59_00.png
-
revo about 6 yearsYou don't have
api_worker
user butapi_workers
(Watchs
). Try with'api_workers'@'%'
. -
Shaharyar about 6 yearsYes, I just realized that and I can't explain how embarrassed I am. It worked with
api_workers
.. -
revo about 6 yearsNo problem. You could remove your question if you want as it was a simple typo.
-
Shaharyar about 6 yearsI think we should improve your answer with this little detail, may be helpful for someone in the future.