Mysql中的各种timeout
2015-10-20 17:46
435 查看
在使用MySQL的过程中,你是否遇到了众多让人百思不得其解的Timeout?
那么这些Timeout之后,到底是代码问题,还是不为人知的匠心独具?
本期Out-man,讲述咱们MySQL DBA自己的Timeout。
先看一下比较常见的Timeout参数和相关解释:
connect_timeout
The number of seconds that the mysqld server waits for a connect packet before responding with Bad handshake.
interactive_timeout
The number of seconds the server waits for activity on an interactive connection before closing it.
wait_timeout
The number of seconds the server waits for activity on a noninteractive connection before closing it.
net_read_timeout
The number of seconds to wait for more data from a connection before aborting the read.
net_write_timeout
The number of seconds to wait for a block to be written to a connection before aborting the write.
从以上解释可以看出,connect_timeout在获取连接阶段(authenticate)起作用,interactive_timeout和wait_timeout在连接空闲阶段(sleep)起作用,而net_read_timeout和net_write_timeout则是在连接繁忙阶段(query)起作用。
获取MySQL连接是多次握手的结果,除了用户名和密码的匹配校验外,还有IP->HOST->DNS->IP验证,任何一步都可能因为网络问题导致线程阻塞。为了防止线程浪费在不必要的校验等待上,超过connect_timeout的连接请求将会被拒绝。
即使没有网络问题,也不能允许客户端一直占用连接。对于保持sleep状态超过了wait_timeout(或interactive_timeout,取决于CLIENT_INTERACTIVE标志)的客户端,MySQL会主动断开连接。
即使连接没有处于sleep状态,即客户端忙于计算或者存储数据,MySQL也选择了有条件的等待。在数据包的分发过程中,客户端可能来不及响应(发送、接收、或者处理数据包太慢)。为了保证连接不被浪费在无尽的等待中,MySQL也会选择有条件(net_read_timeout和net_write_timeout)地主动断开连接。
这么多Timeout足以证明MySQL是多么乐于断开连接。而乐于断开连接的背后,主要是为了防止服务端共享资源被某客户端(mysql、mysqldump、页面程序等)一直占用。
转自:http://rdc.taobao.com/blog/dba/html/433_mysql_timeout_analyze.html
那么这些Timeout之后,到底是代码问题,还是不为人知的匠心独具?
本期Out-man,讲述咱们MySQL DBA自己的Timeout。
先看一下比较常见的Timeout参数和相关解释:
connect_timeout
The number of seconds that the mysqld server waits for a connect packet before responding with Bad handshake.
interactive_timeout
The number of seconds the server waits for activity on an interactive connection before closing it.
wait_timeout
The number of seconds the server waits for activity on a noninteractive connection before closing it.
net_read_timeout
The number of seconds to wait for more data from a connection before aborting the read.
net_write_timeout
The number of seconds to wait for a block to be written to a connection before aborting the write.
从以上解释可以看出,connect_timeout在获取连接阶段(authenticate)起作用,interactive_timeout和wait_timeout在连接空闲阶段(sleep)起作用,而net_read_timeout和net_write_timeout则是在连接繁忙阶段(query)起作用。
获取MySQL连接是多次握手的结果,除了用户名和密码的匹配校验外,还有IP->HOST->DNS->IP验证,任何一步都可能因为网络问题导致线程阻塞。为了防止线程浪费在不必要的校验等待上,超过connect_timeout的连接请求将会被拒绝。
即使没有网络问题,也不能允许客户端一直占用连接。对于保持sleep状态超过了wait_timeout(或interactive_timeout,取决于CLIENT_INTERACTIVE标志)的客户端,MySQL会主动断开连接。
即使连接没有处于sleep状态,即客户端忙于计算或者存储数据,MySQL也选择了有条件的等待。在数据包的分发过程中,客户端可能来不及响应(发送、接收、或者处理数据包太慢)。为了保证连接不被浪费在无尽的等待中,MySQL也会选择有条件(net_read_timeout和net_write_timeout)地主动断开连接。
这么多Timeout足以证明MySQL是多么乐于断开连接。而乐于断开连接的背后,主要是为了防止服务端共享资源被某客户端(mysql、mysqldump、页面程序等)一直占用。
转自:http://rdc.taobao.com/blog/dba/html/433_mysql_timeout_analyze.html
相关文章推荐
- MySQL编码问题
- mysql 命令
- mysql常用语句
- mysql explain 中type的归纳
- 【MySQL】【leetcode】 Employees Earning More Than Their Managers解题报告
- 【MySQL】【leetcode】 Duplicate Emails解题报告
- ubuntu mysql使用
- 新安装的Mysql5.5数据库使用mybatis提示插入数据成功并且主键已经自增,但是数据表中没有数
- mac下安装mysql5.6.27和MySQLWorkbench问题解决办法
- MYSQL数据库使用UTF-8中文编码乱码的解决办法
- Hibernate 因别名引起的Column Not Found(Mysql)
- vs2013添加mysql对EF的支持(转+说明)
- Mysql Exists 和Not Exists用法
- Mysql字符串字段判断是否包含某个字符串的3种方法
- mysql事务
- mysql ga rc beta alpha区别
- MySql常用的存储引擎
- mysql导入导出汇总
- 【MySQL】【leetcode】 Customers Who Never Order解题报告
- 用命令创建MySQL数据库(de1)