MySQL调用函数报错:ERROR 1370 (42000): execute command denied to user 'test'@'localhost' for routine 'mydb.myfunc'
在MySQL调用函数报错:
ERROR 1370 (42000): execute command denied to user 'test'@'localhost' for routine 'mydb.myfunc'
从错误可以看出,用户test是没有execute权限。
添加授权
mysql> grant execute on mydb.* to 'test'@'localhost';
mysql> flush privileges;
授权后重新调用函数:
mysql> call myfunc();
ERROR 1370 (42000): execute command denied to user 'test'@'localhost' for routine 'mydb.myfunc'
仍然报错!
原因是对函数授权不能直接授权给数据库,需要授权到function
mysql> grant execute on function mydb.myfunc to 'test'@'localhost';
mysql> flush privileges;
调用成功!