第42期 MySQL存储过程报错noAccessToProcedureBodies

来源:这里教程网 时间:2026-03-01 18:30:34 作者:

问题描述:在JAVA中调用MYSQL存储过程遇到以下报错: Request Exception 】请求终端:、请求客户端: 101.2*.1*.** 、请求路径: http://eap//definition/rate/uploadRateFile 、请求入参:、 Exception org.springframework.dao.TransientDataAccessResourceException: CallableStatementCallback; SQL []; User does not have access to metadata required to determine stored procedure parameter types. If rights can not be granted, configure connection with "noAccessToProcedureBodies=true" to have driver generate parameters that represent INOUT strings irregardless of actual parameter types.; nested exception is java.sql.SQLException: User does not have access to metadata required to determine stored procedure parameter types. If rights can not be granted, configure connection with "noAccessToProcedureBodies=true" to have driver generate parameters that represent INOUT strings irregardless of actual parameter types. at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:108) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:82) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:82) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1099) at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1135) at com.aeonlife.riskmanager.definition.service.impl.RateServiceImpl.createPartition(RateServiceImpl.java:275) at com.aeonlife.riskmanager.definition.service.impl.RateServiceImpl.createPartitions(RateServiceImpl.java:256) at com.aeonlife.riskmanager.definition.service.impl.RateServiceImpl.uploadRate(RateServiceImpl.java:113) 问题分析: 出现这个错误的原因是 低权用户调用高权用户创建的存储过程出错。 首先,一般情况应该在服务器为数据库建立一个单独的账号,以用于管理数据库,并且该用户权限应被严格控制。而在登录SQL数据库时,应使用创建的单独账号进行数据库一些DLL定义,如建立触发器、函数、存储过程。 尤其是存储过程,因为如果是root等高权限用户建立的存储过程,低权用户访问可能出现: 【Userdoes not have access to metadata required to determine stored procedureparameter types. If rights can not be granted, configure connection with"noAccessToProcedureBodies=true" to have driver generateparameters that represent INOUT strings irregardless of actual parametertypes.】 类似错误。原因在于低权用户访问了高权用户创建的存储过程。 问题的解决方案有三种方法: 1.在连接MySQL的URL中添加参数,jdbc:mysql://2x.1x.3x.1x:3306/dbname?autoReconnect=true&failOverReadOnly=false&useUnicode=true&characterEncoding=utf8&useSSL=false& noAccessToProcedureBodies=true 2.给连接用户授权权限:GRANT SELECT ON mysql.proc TO 'user'@'localhost';  3.右键该存储过程,选择对象属性,将定义者修改为连接用户(也就是权限低的用户)或者使用命令修改。 mysql>update mysql.proc set DEFINER='usename' WHERE NAME='proc_name' AND db='testdb';  

相关推荐