java.sql.SQLException: The user specified as a definer ('userxxx'@'%') does not e...

一个人想着一个人 提交于 2021-02-02 05:53:11

java.sql.SQLException: The user specified as a definer ('userxxx'@'%') does not exist

 

Java接口在执行查询的时候报错如下:

java.sql.SQLException: The user specified as a definer ('userxxx'@'%') does not exist

错误详情:

2019-12-24 14:18:44 [ ERROR ]  [DUBBO] Got unchecked and undeclared exception which called by 10.11.22.2. service: com.imodule.report.service.report.workflow.ReportService, method: queryNewSingleCase, exception: org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1449];   
--- The error occurred in com/imodule/report/dao/sqlmap/kpiRptnwf.xml.  
--- The error occurred while applying a parameter map.  
--- Check the kpiRptnwf.queryNewSingleCase-InlineParameterMap.  
--- Check the statement (query failed).  
--- Cause: java.sql.SQLException: The user specified as a definer ('userxxx'@'%') does not exist; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/imodule/report/dao/sqlmap/kpiRptnwf.xml.  
--- The error occurred while applying a parameter map.  
--- Check the kpiRptnwf.queryNewSingleCase-InlineParameterMap.  
--- Check the statement (query failed).  
--- Cause: java.sql.SQLException: The user specified as a definer ('userxxx'@'%') does not exist, dubbo version: 2.4.9, current host: 10.11.22.2
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1449];   
--- The error occurred in com/imodule/report/dao/sqlmap/kpiRptnwf.xml.  
--- The error occurred while applying a parameter map.  
--- Check the kpiRptnwf.queryNewSingleCase-InlineParameterMap.  
--- Check the statement (query failed).  
--- Cause: java.sql.SQLException: The user specified as a definer ('userxxx'@'%') does not exist; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/imodule/report/dao/sqlmap/kpiRptnwf.xml.  
--- The error occurred while applying a parameter map.  
--- Check the kpiRptnwf.queryNewSingleCase-InlineParameterMap.  
--- Check the statement (query failed).  
--- Cause: java.sql.SQLException: The user specified as a definer ('userxxx'@'%') does not exist
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
        at com.imodule.frame.dao.ClioSqlMapClient.execute(ClioSqlMapClient.java:153)
        at com.imodule.frame.dao.ClioSqlMapClient.queryForList(ClioSqlMapClient.java:247)
        at com.imodule.report.dao.impl.KPIRptnwfDao.queryNewSingleCase(KPIRptnwfDao.java:174)
        at com.imodule.report.service.report.workflow.ReportServiceImpl.queryNewSingleCase(ReportServiceImpl.java:1035)
        at com.alibaba.dubbo.common.bytecode.Wrapper10.invokeMethod(Wrapper10.java)
        at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)
        at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)
        at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)
        at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
        at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
        at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
        at com.jd.bdp.hydra.dubbo.HydraFilter.invoke(HydraFilter.java:75)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
        at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
        at com.alibaba.dubbo.rpc.filter.ExecuteLimitFilter.invoke(ExecuteLimitFilter.java:50)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
        at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:60)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
        at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:112)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
        at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
        at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38)
        at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
        at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:108)
        at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:84)
        at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170)
        at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52)
        at com.alibaba.dubbo.remoting.transport.dispather.ChannelEventRunnable.run(ChannelEventRunnable.java:82)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/imodule/report/dao/sqlmap/kpiRptnwf.xml.  
--- The error occurred while applying a parameter map.  
--- Check the kpiRptnwf.queryNewSingleCase-InlineParameterMap.  
--- Check the statement (query failed).  
--- Cause: java.sql.SQLException: The user specified as a definer ('userxxx'@'%') does not exist
        at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
        at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
        at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
        at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
        at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
        at com.imodule.frame.dao.ClioSqlMapClient$3.doInSqlMapClient(ClioSqlMapClient.java:249)
        at com.imodule.frame.dao.ClioSqlMapClient$3.doInSqlMapClient(ClioSqlMapClient.java:247)
        at com.imodule.frame.dao.ClioSqlMapClient.execute(ClioSqlMapClient.java:150)
        ... 35 more
Caused by: java.sql.SQLException: The user specified as a definer ('userxxx'@'%') does not exist
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
        at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
        at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)
        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 com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(PreparedStatementLogProxy.java:62)
        at com.sun.proxy.$Proxy17.execute(Unknown Source)
        at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185)
        at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
        at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
        ... 42 more

一开始是怀疑当前接口调用的sql脚本里面是不是包含了函数(存储过程之类的),仔细检查后发现当前接口的sql里面没有类似的调用呀.....

然后才发现是数据库用户名变更,在定义的函数里面没有变更对应的数据库用户名

eg: 原来数据库中的用户是 useryyy ,定义函数的时候也是用的 useryyy ;后来数据库变更,将用户useryyy改为了userxxx,但是函数的定义用户没有更改,还是原来的用户 useryyy。

 

解决方案:

使用root用户登录数据库,将对应的函数定义者更改为 新的用户即可。(useryyy --> userxxx)

参考下图: (将下图的定义者更改为当前登录数据库(需要从数据库中查询数据的用户)的用户即可)

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!