mysql timeout
(待更新整理)
因?yàn)樽罱龅揭恍┏瑫r(shí)的問題,正好就把所有的timeout參數(shù)都理一遍,首先數(shù)據(jù)庫里查一下看有哪些超時(shí):
| 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 | # 這個(gè)參數(shù)已經(jīng)沒用了 | wait_timeout | 172800 | +----------------------------+--------+ |
我們一個(gè)個(gè)來看
目錄 (Contents)?[隱藏 (Hide)]
- 1?connect_timeout
- 2?delayed_insert_timeout
- 3?innodb_lock_wait_timeout
- 4?innodb_rollback_on_timeout
- 5?interactive_timeout/wait_timeout
- 6?net_read_timeout / net_write_timeout
- 7?slave_net_timeout
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.
解釋:在獲取鏈接時(shí),等待握手的超時(shí)時(shí)間,只在登錄時(shí)有效,登錄成功這個(gè)參數(shù)就不管事了。主要是為了防止網(wǎng)絡(luò)不佳時(shí)應(yīng)用重連導(dǎo)致連接數(shù)漲太快,一般默認(rèn)即可。
delayed_insert_timeout
手冊描述:
How many seconds an INSERT DELAYED handler thread should wait for INSERT statements before terminating.
解釋:這是為MyISAM INSERT DELAY設(shè)計(jì)的超時(shí)參數(shù),在INSERT DELAY中止前等待INSERT語句的時(shí)間。
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.
解釋:描述很長,簡而言之,就是事務(wù)遇到鎖等待時(shí)的Query超時(shí)時(shí)間。跟死鎖不一樣,InnoDB一旦檢測到死鎖立刻就會(huì)回滾代價(jià)小的那個(gè)事務(wù),鎖等待是沒有死鎖的情況下一個(gè)事務(wù)持有另一個(gè)事務(wù)需要的鎖資源,被回滾的肯定是請求鎖的那個(gè)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.
解釋:這個(gè)參數(shù)關(guān)閉或不存在的話遇到超時(shí)只回滾事務(wù)最后一個(gè)Query,打開的話事務(wù)遇到超時(shí)就回滾整個(gè)事務(wù)。
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
解釋:一個(gè)持續(xù)SLEEP狀態(tài)的線程多久被關(guān)閉。線程每次被使用都會(huì)被喚醒為acrivity狀態(tài),執(zhí)行完Query后成為interactive狀態(tài),重新開始計(jì)時(shí)。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.
解釋:這個(gè)參數(shù)只對TCP/IP鏈接有效,分別是數(shù)據(jù)庫等待接收客戶端發(fā)送網(wǎng)絡(luò)包和發(fā)送網(wǎng)絡(luò)包給客戶端的超時(shí)時(shí)間,這是在Activity狀態(tài)下的線程才有效的參數(shù)
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判斷主機(jī)是否掛掉的超時(shí)設(shè)置,在設(shè)定時(shí)間內(nèi)依然沒有獲取到Master的回應(yīng)就人為Master掛掉了
【參考資料】
1、http://www.penglixun.com/tech/database/mysql_timeout.html
2、http://www.ttlsa.com/mysql/research-and-measurement-of-timeout-mysql/
轉(zhuǎn)載于:https://www.cnblogs.com/gsblog/p/4046526.html
總結(jié)
以上是生活随笔為你收集整理的mysql timeout的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Eclipse上GIT插件EGIT使用手
- 下一篇: Mysql找不到mysql.sock怎么