[Err] 1370 - execute command denied to user

问题描述:
Mysql中UserA 调用UserB的函数时遇到
[Err] 1370 - execute command denied to user ‘test’@’127.0.0.1’ for routine ‘lw.historynextval’

查看UserA的权限
mysql> show grants for UserA@192.168.10.61;
GRANT EXECUTE ON FUNCTION lw.historynextval TO ‘UserA’@’192.168.10.61’

UserA调用UserB的函数,返回[Err] 1370,Why?
mysql -uUserA -p -h 127.0.0.1 -P 3316 -e “select lw.historynextval()”
[Err] 1370 - execute command denied to user ‘test’@’127.0.0.1’ for routine ‘lw.historynextval’

用UserB调用自己定义的函数,返回ERROR 1370 (42000)
mysql -uUserB -p -h 127.0.0.1 -P 3316 -e “select lw.historynextval()”
Enter password:
ERROR 1370 (42000) at line 1: execute command denied to user ‘test’@’127.0.0.1’ for routine ‘lw.historynextval’

从错误的描述来看是,UserB没有执行自己定义函数的权限

授权给UserB执行函数的权限
GRANT EXECUTE ON lw.* TO ‘test’@’127.0.0.1’;

用UserB调用自己定义的函数,成功。
mysql -utest -p -h 127.0.0.1 -P 3316 -e “select lw.historynextval()”
Enter password:
+———————+
| lw.historynextval() |
+———————+
| 21 |
+———————+

UserA调用UserB的函数,成功。
mysql -uUserA -p -h 127.0.0.1 -P 3316 -e “select lw.historynextval()”
+———————+
| lw.historynextval() |
+———————+
| 22 |
+———————+

Mysql中调用其它用户定义的函数时:
1.首先要确保函数的定义者有执行自己定义函数的权限。
如:用户A,创建了函数fun1。首先要保证用户A能调用函数fun1.

2.函数的调用者要有调用函数的权限
用户B要调用A用户定义的函数fun1,要确保用户B被授权调用A用户的函数

3.如果函数中涉及到对相关表的权限,也要授予函数的调用者。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值