【基础知识思考整理】MySQL数据库中的超时值timeout

本文介绍了MySQL中的三种超时配置:Connect_timeout、interactive_timeout及wait_timeout。分别解释了它们的作用,如握手超时、交互式连接空闲超时及普通连接空闲超时等,并提供了如何调整这些设置的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基础知识思考整理
http://blog.csdn.net/aganlengzi/article/details/51933601

数据库中关于超时时间的值:

这里写图片描述

Connect_timeout:

The number of seconds that the mysqld server waits for a connect packet before respondingwith Bad handshake. The default value is 10 seconds as of MySQL 5.1.23 and 5 seconds before that. 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.
解释:在获取链接时,等待握手的超时时间,只在登录时有效,登录成功这个参数就不管事了。主要是为了防止网络不佳时应用重连导致连接数涨太快,一般默认即可。

interactive_timeout:

The number of seconds the server waits for activity on an interactive connection before closing it. An interactive client is defined as a client that uses the CLIENT_INTERACTIVE option to mysql_real_connect(). See also wait_timeout.
interactive_timeout 需在mysql_connect()设置CLIENT_INTERACTIVE选项后起作用,并被赋值为wait_timeout,如果要启用,记得在调用连接函数的时候加上这个属性参数。

Wait_timeout:

一个连接connection空闲超过8个小时(默认值28800秒),MySQL就会自动断开这个连接。Wait_timeout值可以设定,但是最大是1-2147483(Windows),1-31536000(linux)。我们mini项目中因为超时值问题出想过一次down机,但是后台的脚本自动将进程又拉起来了,所以没有出现功能上的问题。

修改方法:

在配置文件mysql.ini中进行设置
添加类似wait_timeout=xxxx的语句即可
通过命令行进行修改
Mysql> set global wait_timeout=xxxx;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值