mysql 创建函数 权限_MySQL赋予用户执行自定义Function的权限

在启动项目时遇到'execute command denied to user'错误,由于用户缺少执行自定义Function的权限。通过检查grants并为用户cxcs授予execute权限解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

395c595fae8da1cbb9c380cc26be3951.png

将远程数据库导入到本地之后,一启动项目就报错“execute command denied to user”,提示用户没权限执行自定义FunctionCaused by: java.sql.SQLSyntaxErrorException: execute command denied to user 'cxcs'@'localhost' for routine 'hzcx.getOrgName'

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)

at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:975)

at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:392)

at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)

at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)

at sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:55)

at com.sun.proxy.$Proxy25.execute(Unknown Source)

at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:56)

at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70)

at sun.reflect.GeneratedMethodAccessor49.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:59)

at com.sun.proxy.$Proxy23.query(Unknown Source)

at org.apache.ibatis.executor.ReuseExecutor.doQuery(ReuseExecutor.java:54)

at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259)

at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132)

at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)

at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:354)

... 19 more

检查导入sql,发现这个function是在root用户下面的,所以将已定义的function全部删除重建,全部在cxcs这个用户下面,结果发现还是不行,错误依旧。

后来查阅资料时,看到有博主碰到过用户没有给execute权限的情况:http://blog.csdn.net/lwei_998/article/details/44177741

想起来好像自己也没有给用户赋予执行权限,使用show命令查看一下show grants for 'cxcs'@'localhost'

果然是这个原因,用户cxcs只有“select,insert,update,delete,create,drop,alter”这几个权限,赶紧grant一个execute给用户cxcsgrant execute on hzcx.* to 'cxcs'@'localhost'

问题解决!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值