MySQL 创建存储过程时是否需要`definer`?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2666286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is `definer` required when creating a stored procedure?
提问by Xorty
I've written all of MySQL procedures as root@localhost
:
我已将所有 MySQL 程序编写为root@localhost
:
CREATE DEFINER=`root`@`localhost` PROCEDURE `p_add_user`(...)
Trouble is, when deploying to another server, I have to replace root
with current user and replace localhost
with current IP, which is annoying.
麻烦的是,在部署到另一台服务器时,我必须替换root
为当前用户并替换localhost
为当前IP,这很烦人。
Is there any way to write procedures so that someone who wants to use my database and procedures would not have to modify the definer of each procedure?
有什么方法可以编写程序,以便想要使用我的数据库和程序的人不必修改每个程序的定义者?
采纳答案by maid450
回答by MonkeyFeeder
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-programs-security.html
这样做,将应用实际的调用者权限,并DEFINER
省略该部分(即使在模式导入期间自动添加)。完整参考:https:
//dev.mysql.com/doc/refman/5.7/en/stored-programs-security.html
回答by Ghulam Dastagir - Yasir
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...
检查它.. 可能这会帮助你,如果你想在你的程序中定义用户......