您的位置:首页 > 数据库 > MySQL

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

2016-07-17 18:29 633 查看
基础知识思考整理

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息