Grant Execute Function permission to another user

12,304

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.

Share:
12,304
Shaharyar
Author by

Shaharyar

Recipe For Handling Rapid Growth while (true) { identify_and_fix_bottlenecks(); eat(); sleep(); notice_new_bottleneck(); } Contact: [email protected]

Updated on June 26, 2022

Comments

  • Shaharyar
    Shaharyar about 2 years

    I have a database function fn_relation_isModerator, only user api 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
      Michael about 6 years
      Are you trying to do it as root?
    • Shaharyar
      Shaharyar about 6 years
      @MichaelO. Yes!
    • Michael
      Michael about 6 years
      Your second approach is correct. Maybe try creating the user?
    • Shaharyar
      Shaharyar about 6 years
      It already exists
  • Shaharyar
    Shaharyar about 6 years
    I already tried it, mentioned in Approach 2. Resulted with error Error Code: 1133. Can't find any matching row in the user table
  • revo
    revo about 6 years
    Sorry I think I missed it. Then it means api_worker user on % host doesn't exist yet. Do a SELECT CONCAT(User, '@', Host) FROM mysql.user; to confirm.
  • revo
    revo about 6 years
    Did you run that select query?
  • Shaharyar
    Shaharyar about 6 years
    Which query? Sorry didn't get your reference?
  • revo
    revo about 6 years
    No problem: SELECT CONCAT(User, '@', Host) FROM mysql.user;
  • Shaharyar
    Shaharyar about 6 years
  • revo
    revo about 6 years
    You don't have api_worker user but api_workers (Watch s). Try with 'api_workers'@'%'.
  • Shaharyar
    Shaharyar about 6 years
    Yes, I just realized that and I can't explain how embarrassed I am. It worked with api_workers..
  • revo
    revo about 6 years
    No problem. You could remove your question if you want as it was a simple typo.
  • Shaharyar
    Shaharyar about 6 years
    I think we should improve your answer with this little detail, may be helpful for someone in the future.