当前位置:网站首页>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:则是在连接执行时起作用。
参考文档:
边栏推荐
- uni-app installs components using npm commands
- Volatility memory forensics - command shows
- 线程的5种状态
- POI工具类
- CTF之misc-日志分析
- CTF之misc-图片隐写
- The Request request body is repackaged to solve the problem that the request body can only be obtained once
- Extraction of BaseDAO
- Bubble sort, selection sort, insertion sort, quick sort
- Flink CDC implements Postgres to MySQL streaming processing transmission case
猜你喜欢

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

sql中 exists的用法

MySQL数据库之JDBC编程

npm run serve启动报错npm ERR Missing script “serve“

Using PyQt5 to add an interface to YoloV5 (1)

The operations engineer interview experience

c#下Web3合约空投、转账调用代码

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

Flink CDC implements Postgres to MySQL streaming processing transmission case

FastAPI Quick Start
随机推荐
oracle row to column, column to row summary
记一次流量分析实战——安恒科技(八月ctf)
连接云服务器Docker中的Mysql 详细图文操作(全)
sql中 exists的用法
Flink PostgreSQL CDC配置和常见问题
Mycat2.0搭建教程
awd --waf deployment
Competition WP in May
根据ip地址获取地理位置及坐标(离线方式)
Online sql editing query tool sql-editor
misc-log analysis of CTF
CTF之misc-图片隐写
JVM Learning (2) Garbage Collector
文件上传漏洞的绕过
CTF misc-audio and video steganography
【十年网络安全工程师整理】—100渗透测试工具使用方法介绍
TDengineGUI无法连接TDengine
torch distributed training
DVWA安装教程(懂你的不懂·详细)
mysql is not an internal or external command, nor is it a runnable program or batch file to resolve