Rails Mysql2::Error: closed MySQL connection 报错

最近遇到一个问题,查询数据库的时候报了一个Mysql2::Error: closed MySQL connection 的错误。为什么会出现这种错误呢?我分析了一下:

我使用的是mysql,姑且用mysql服务做说明。

mysql server有个配置项:wait_timeout,我们查查官方文档:

connect_timeout
Command-Line Format	--connect_timeout=#
System Variable	Name	connect_timeout
Variable Scope	Global
Dynamic Variable	Yes
Permitted Values	Type	integer
Default	10
Min Value	2
Max Value	31536000

The number of seconds that the mysqld server waits for a connect packet before responding with Bad handshake. The default value is 10 seconds.

Increasing the connect_timeout value might help if clients frequently encounter errors of the form Lost connection to MySQL server at 'XXX', system error: errno. 
不仔细解释了,这个配置项的意思就是一个数据库连接的等待超时时间,就是说,如果一个连接建立之后,如果超过这个时间没有操作,这个连接就会断开。

基于这个知识点,我来解释一下我为什么会出现这个错误。
我的使用场景是启动一个进程,在这个进程里会得到别的服务推送过

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值