因为最近遇到一些超时的问题,正好就把所有的timeout参数都理一遍,首先数据库里查一下看有哪些超时:
root@localhost : test 12:55:50> show global variables like "%timeout%"; +----------------------------+--------+ | Variable_name | Value | +----------------------------+--------+ | connect_timeout | 10 | | delayed_insert_timeout | 300 | | innodb_lock_wait_timeout | 120 | | innodb_rollback_on_timeout | ON | | interactive_timeout | 172800 | | net_read_timeout | 30 | | net_write_timeout | 60 | | slave_net_timeout | 3600 | | table_lock_wait_timeout | 50 | # 这个参数已经没用了 | wait_timeout | 172800 | +----------------------------+--------+ |
我们一个个来看
connect_timeout
手册描述:
The number of seconds that the mysqld server waits for a connect packet before responding with 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.
解释:在获取链接时,等待握手的超时时间,只在登录时有效,登录成功这个参数就不管事了。主要是为了防止网络不佳时应用重连导致连接数涨太快,一般默认即可。
delayed_insert_timeout
手册描述:
How many seconds an INSERT DELAYED handler thread should wait for INSERT statements before terminating.
解释:这是为MyISAM INSERT DELAY设计的超时参数,在INSERT DELAY中止前等待INSERT语句的时间。
innodb_lock_wait_timeout
手册描述:
The timeout in seconds an InnoDB transaction may wait for a row lock before giving up. The default value is 50 seconds. A transaction that tries to access a row that is locked by another InnoDB transaction will hang for at most this many seconds before issuing the following error:
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction |
When a lock wait timeout occurs, the current statement is not executed. The current transaction is not rolled back. (To have the entire transaction roll back, start the server with the –innodb_rollback_on_timeout option, available as of MySQL 5.1.15. See also Section 13.6.12, “InnoDB Error Handling”.)
innodb_lock_wait_timeout applies to InnoDB row locks only. A MySQL table lock does not happen inside InnoDB and this timeout does not apply to waits for table locks.
InnoDB does detect transaction deadlocks in its own lock table immediately and rolls back one transaction. The lock wait timeout value does not apply to such a wait.
For the built-in InnoDB, this variable can be set only at server startup. For InnoDB Plugin, it can be set at startup or changed at runtime, and has both global and session values.
解释:描述很长,简而言之,就是事务遇到锁等待时的Query超时时间。跟死锁不一样,InnoDB一旦检测到死锁立刻就会回滚代价小的那个事务,锁等待是没有死锁的情况下一个事务持有另一个事务需要的锁资源,被回滚的肯定是请求锁的那个Query。
innodb_rollback_on_timeout
手册描述:
In MySQL 5.1, InnoDB rolls back only the last statement on a transaction timeout by default. If –innodb_rollback_on_timeout is specified, a transaction timeout causes InnoDB to abort and roll back the entire transaction (the same behavior as in MySQL 4.1). This variable was added in MySQL 5.1.15.
解释:这个参数关闭或不存在的话遇到超时只回滚事务最后一个Query,打开的话事务遇到超时就回滚整个事务。
interactive_timeout/wait_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
解释:一个持续SLEEP状态的线程多久被关闭。线程每次被使用都会被唤醒为acrivity状态,执行完Query后成为interactive状态,重新开始计时。wait_timeout不同在于只作用于TCP/IP和Socket链接的线程,意义是一样的。
net_read_timeout / net_write_timeout
手册描述:
The number of seconds to wait for more data from a connection before aborting the read. Before MySQL 5.1.41, this timeout applies only to TCP/IP connections, not to connections made through Unix socket files, named pipes, or shared memory. When the server is reading from the client, net_read_timeout is the timeout value controlling when to abort. When the server is writing to the client, net_write_timeout is the timeout value controlling when to abort. See also slave_net_timeout.
On Linux, the NO_ALARM build flag affects timeout behavior as indicated in the description of the net_retry_count system variable.
解释:这个参数只对TCP/IP链接有效,分别是数据库等待接收客户端发送网络包和发送网络包给客户端的超时时间,这是在Activity状态下的线程才有效的参数
slave_net_timeout
手册描述:
The number of seconds to wait for more data from the master before the slave considers the connection broken, aborts the read, and tries to reconnect. The first retry occurs immediately after the timeout. The interval between retries is controlled by the MASTER_CONNECT_RETRY option for the CHANGE MASTER TO statement or –master-connect-retry option, and the number of reconnection attempts is limited by the –master-retry-count option. The default is 3600 seconds (one hour).
解释:这是Slave判断主机是否挂掉的超时设置,在设定时间内依然没有获取到Master的回应就人为Master挂掉了
http://blog.chinaunix.net/uid-20639775-id-3180980.html
相关推荐
mysql>show gloable variables like “%timeout%”; 进行查看 interactive_timeout 的黓认值为28800 wait_timeout 的默认值这:120 根据情况增加吧. 这两个值是一个全局变量,可以动态增加,如: mysql> set ...
MySQL的`wait_timeout`连接超时问题通常出现在长时间无操作的数据库连接上,服务器会自动关闭这些连接以释放资源。这种现象在应用中可能导致突然的数据通信中断,表现为“Communications link failure”等错误,提示...
在MySQL中,`interactive_timeout` 和 `wait_timeout` 是两个重要的配置参数,它们与客户端连接到服务器的超时设置紧密相关。理解这两个参数的区别对于优化数据库性能和避免不必要的连接断开至关重要。 `...
2. 查看 wait_timeout 参数的值:可以通过 SHOW GLOBAL VARIABLES 命令来查看 wait_timeout 参数的值,例如:mysql> show global variables like 'wait_timeout'; 这将显示当前的 wait_timeout 值。 3. 避免使用 ...
6. `connect_timeout`: 这个参数定义了MySQL服务器在等待客户端完成连接握手过程的最长时间。如果超过这个时间,服务器将发送“Bad handshake”错误并关闭连接。默认值为10秒,防止因网络延迟或客户端问题导致的无尽...
在 MySQL 中,wait_timeout 参数是控制连接超时的关键参数。当该参数设置的太大时,可能会导致 MySQL 中大量的 SLEEP 进程无法及时释放,拖累系统性能。然而,如果将其设置的太小,可能会遭遇到“MySQL has gone ...
- `net.ipv4.tcp_fin_timeout=30`:缩短TIME_WAIT状态的持续时间,单位为秒。 2. **使配置生效**:执行`sysctl -p`命令,使修改后的参数立即生效。 ### 三、优化MySQL配置 除了系统层面的优化,对MySQL数据库...
MySQL的`slave_net_timeout`参数在数据库集群环境中扮演着重要的角色,它关乎主从复制的稳定性和效率。本文将深入探讨这个参数,并基于一个实际案例解释如何利用它来解决集群问题。 在升级一套数据库集群从MySQL ...
MySQL数据库的连接超时问题,通常表现为Wait_timeout错误,指的是当客户端与服务器之间的连接在指定时间内没有进行任何数据交互,数据库会自动断开这个连接,以释放资源并防止不必要的资源占用。这一特性在MySQL中是...
wait_timeout =86400 相关参数,红色部分 mysql> show variables like ‘%timeout%’; +————————–+——-+ | Variable_name | Value | +————————–+——-+ | connect_timeout | 5 | | delayed_i
在MySQL数据库操作中,"SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded" 是一个常见的错误,它意味着在执行事务时,系统等待锁定资源的时间超过了预设的限制。这个错误通常发生在并发环境中,当...
下面我们将详细讨论与"timeout"相关的IT知识点。 1. **超时(Timeout)**: - 超时是计算机系统中用来处理长时间无响应或等待过程的一种机制。当一个操作在预设的时间内没有完成,系统就会触发超时事件,通常会...
使用Entity Framework 6.1.X连接MySQL5.7存在的几个问题的解决办法. 1.选择EF版本,弹出Your project references the latest version of EF;however,an EF database provider compatible with this version could ...
3. **show variables like ‘%timeout%’** 和 **show variables like ‘%packet%’**: 这两条命令用于查看当前MySQL服务器的这些参数值,帮助诊断问题或确认调整是否生效。 在服务器环境中,调整这些参数后,务必...
wait_timeout 参数控制着 MySQL 客户端的数据库连接闲置最大时间值。默认的 wait_timeout 值为 8 小时,这个值太大,可能会导致连接数爆炸。通过修改 wait_timeout 值为 30 分钟,可以减少连接数的爆炸风险。 修改 ...
虽然不是直接由头文件提供,但可以使用`mysql_options()`设置`MYSQL_OPT_RECONNECT`和`MYSQL_OPT_CONNECT_TIMEOUT`等相关选项来管理连接池。 以上就是MySQL 5.5版头文件中的核心知识点。了解并熟练运用这些函数和...