当前位置:   article > 正文

Mysql 异常,“Cause: com.mysql.cj.jdbc.exceptions.MySQLTimeoutException”_statement cancelled due to timeout or client reque

statement cancelled due to timeout or client request

Cause: com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request

简言:这种异常从字面翻译过来:mysql 请求链接超时,具体超时是什么原因导致的,可以根据情况分析下。

异常详情

org.springframework.dao.QueryTimeoutException: 
### Error updating database.  Cause: com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request
### The error may exist in file [/app/resources/mybatis/YouDouRecordMapper.xml]
### The error may involve com.txxy.activity.mapper.YouDouRecordMapper.insert-Inline
### The error occurred while setting parameters
### SQL: insert into youdou_record(                   id, u_id, change_Amount, source_id, source_name, type, create_time, create_user, modify_time, modify_user               ) values(null, ?, ?, ?, ?, ?, now(), ?, now(), ?)
### Cause: com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request
; Statement cancelled due to timeout or client request; nested exception is com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request
	at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:76) ~[spring-jdbc-5.3.22.jar:5.3.22]
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70) ~[spring-jdbc-5.3.22.jar:5.3.22]
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79) ~[spring-jdbc-5.3.22.jar:5.3.22]
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88) ~[mybatis-spring-2.0.5.jar:2.0.5]
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440) ~[mybatis-spring-2.0.5.jar:2.0.5]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

问题分析原因:当前业务上线已经有半年,突然监控到异常。分析原因,应该不是代码错误导致,不然问题早就被抛出来,那就是网络或是DB被占用资源请求队列阻塞原因导致请求超时。

分析工具:阿里云数据库监控平台
在这里插入图片描述
通过上面监控盘可以观察到数据库再这时间段有明显波动,找DBA确认有执行其它业务

具体操作:

altel table youdou_record convert to character set utf8m64_general_ci;
这语句意思是修改youdou_record  表字符集
  • 1
  • 2

语句执行,会锁表,导致JDBC 连接数据库,执行inset 语句插入数据,抛出请求超时,同时数据库连接池堆栈信息也同步增长。

问题就分析到这了。

扩展

上问题因业务而异,也有可能是其它原因,下面给大家做个罗列

1.配置jdbc超时时间,适当增大,在JDBC连接参数里加上queryTimeout=2400即可解决。
2.加索引,优化SQL,给关联字段增加索引
3.子查询尽量缩小搜索范围,减少join的次数
4.能用join就不要in了
5.限制索引的数目
6.不要查询*(所有),避免大字段,查询需要信息即可

以上资料仅供参考,欢迎大家留言讨论~ ღ( ´・ᴗ・` )比心

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/1006768
推荐阅读
相关标签
  

闽ICP备14008679号