当前位置:网站首页>Mysql 客户端常见异常分析
Mysql 客户端常见异常分析
2022-07-30 05:43:00 【若明天不见】
SocketTimeoutException
jdbc timeout包括Transaction Timeout/Statement Timeout/connectTimeout/socketTimeout四种类型,详细解释可见Jdbc & Mysql timeout分析
如果与服务器连接成功,即开始数据传输。如果服务器处理数据用时过长,超过了socketTimeout,就会抛出SocketTimeOutExceptin,即服务器响应超时
建议在jdbc url param中显示配置connectTimeout/socketTimeout,有效控制MySQL处理时间,并释放连接
jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&connectTimeout=3000&socketTimeout=5000
CommunicationsException
若发生 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 异常,为数据库连接失效,但是失效的原因可能会有多种,大致都与 mysql 各种 timeout 参数相关
EOFException
net_write_timeout 控制 mysql server向客户端写数据超时时间。若客户端建立连接后,超过该时间MySQL仍未写完数据,则会抛出EOFException
java.io.EOFException: Can not read response from server. Expected to read 34328 bytes, read 433 bytes before connection was unexpectedly lost.
SocketException
jdbc连接会根据 mysql wait_timeout 检测空闲连接。若在 wait_timeout 时间内,连接还是空闲状态,mysql server将会断开这个链接。
与
MySQL建立连接成功后,MySQL主动断开连接,底层异常却为java.net.SocketException: Software caused connection abort: recv failed
SocketTimeoutException
sql执行时间超过socketTimeout的配置,则会抛出java.net.SocketTimeoutException: Read timed out
RecoverableDataAccessException
使用了已断开的MySQL连接,会抛出org.springframework.dao.RecoverableDataAccessException
附表(MySQL timeout参数)
SHOW VARIABLES LIKE '%timeout%';可查看MySQL timeout参数
| 参数 | 描述 | 功能 |
|---|---|---|
| connect_timeout | 连接响应超时时间 | 服务器端在这个时间内如未连接成功,则会返回连接失败。 |
| wait_timeout | 连接空闲超时时间 | 与服务器端无交互状态的连接,直到被服务器端强制关闭而等待的时间。可以认为是服务器端连接空闲的时间,空闲超过这个时间将自动关闭 |
| interactive_timeout | 连接空闲超时时间 | 与服务器端无交互状态的连接,直到被服务器端强制关闭而等待的时间。 |
| net_read_timeout | 数据读取超时时间 | 在终止读之前,从一个连接获得数据而等待的时间秒数;当服务正在从客户端读取数据时,net_read_timeout控制何时超时。即客户端执行数据读取,等待多少秒仍未执行成功时自动断开连接。 |
| net_write_timeout | 数据库写超时时间 | 和net_read_timeout意义类似,在终止写之前,等待多少秒把block写到连接;当服务正在写数据到客户端时,net_write_timeout控制何时超时。 |
| slave-net-timeout | 从库延后同步的时间 | 当slave认为连接master的连接有问题时,就等待N秒,然后断开连接,重新连接master |
interactive_timeout和wait_timeout意义虽然相同,但是有使用对象有本质的区别。interactive_timeout针对交互式连接(比如通过mysql客户端连接数据库),wait_timeout针对非交互式连接(比如一般在PHP中使用PDO连接数据库,当然你可以设置CLIENT_INTERACTIVE选项来改变)。所谓的交互式连接,即在mysql_real_connect()函数中使用了CLIENT_INTERACTIVE选项。
slave-net-timeout在主从同步时从库上起作用;connect_timeout:在获取连接阶段起作用;interactive_timeout和wait_timeout:在连接空闲阶段起作用;net_read_timeout和net_write_timeout:则是在连接执行时起作用。
参考文档:
边栏推荐
猜你喜欢

mysql不是内部或外部命令,也不是可运行的程序或批处理文件解决

Mycat2.0搭建教程

3 minutes to tell you how to become a hacker | Zero foundation to hacker introductory guide, you only need to master these five skills

在不同的服务器上基于docker部署redis主从同步

mysql is not an internal or external command, nor is it a runnable program or batch file to resolve

【Spark】Spark 高频面试题英语版(1)

【小程序项目开发-- 京东商城】uni-app之分类导航区域
Misc-traffic analysis of CTF

C#下利用开源NPlot绘制股票十字交叉线

DVWA installation tutorial (understand what you don't understand · in detail)
随机推荐
【OS】操作系统高频面试题英文版(1)
C# WPF下限制TextBox只输入数字、小数点、删除等键
torch分布式训练
The number of warehouse 】 data quality
Detailed explanation of ClickHouse query statement
Communication middleware Fast DDS basic concepts and communication examples
Thread state of five
uni-app installs components using npm commands
史上超强最常用SQL语句大全
mysql不是内部或外部命令,也不是可运行的程序或批处理文件解决
【数仓】数据仓库高频面试题题英文版(1)
Dcat Admin installation
C#中default关键字用法简介
jsonpath
The Request request body is repackaged to solve the problem that the request body can only be obtained once
Bypassing the file upload vulnerability
互联网商城盲盒app为何如此火爆
Online sql editing query tool sql-editor
【调优】一个 Spark 任务某天突然变慢怎么解决
CTF之misc-音视频隐写