Is `definer` required when creating a stored procedure?

前端 未结 3 1011
遇见更好的自我
遇见更好的自我 2021-02-02 08:54

I\'ve written all of MySQL procedures as root@localhost:

CREATE DEFINER=`root`@`localhost` PROCEDURE `p_add_user`(...)

Trouble is,

相关标签:
3条回答
  • 2021-02-02 09:03
    CREATE DEFINER=[your_web_user]@% PROCEDURE p_add_user(...)
    

    Check it.. probably this will help you, if you want to define the user in your procedure...

    0 讨论(0)
  • 2021-02-02 09:18

    [EDIT: updated ref page]

    You can specify execution privileges by adding the following statement in the procedure body (after declaration):

    SQL SECURITY INVOKER
    

    Example:

    CREATE DEFINER=`root`@`localhost` PROCEDURE `p_add_user`()
    SQL SECURITY INVOKER
    (...)
    

    Doing so, the actual invoker privileges are applied and the DEFINER part is omitted (even when it is auto-added during schema import). Full reference here: https://dev.mysql.com/doc/refman/5.7/en/stored-objects-security.html

    0 讨论(0)
  • 2021-02-02 09:25

    As stated in MySQL documentation here

    CREATE
    [DEFINER = { user | CURRENT_USER }]
    PROCEDURE sp_name ([proc_parameter[,...]])
    [characteristic ...] routine_body
    

    So, the DEFINER part is not mandatory, just CREATE PROCEDURE should work.

    0 讨论(0)
提交回复
热议问题