问题描述:
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.如果函数中涉及到对相关表的权限,也要授予函数的调用者。