mysql连接超时的参数设置_MySQL
最近系统因为数据库连接超时的问题,出现了几次故障。排查了下my.cnf的配置问题,最后是代码设计有问题。正好就把所有的timeout参数都理一遍,首先数据库里查一下看有哪些超时:
mysql> show global variables like "%timeout%";
+-----------------------------+----------+
| Variable_name | Value |
+-----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 120 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 3600 |
| wait_timeout | 28800 |
+-----------------------------+----------+
12 rows in set (0.00 sec)
我们来分析下各个参数的意义:
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:
1
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链接的线程,意义是一样的。一般设置是8小时,一般网站白天都有人访问,从夜里到早上一般都会超过8小时,所以再来访问就会这个问题。
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挂掉了

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PHP5.4版本新功能:如何使用callable類型提示參數接受可呼叫的函數或方法引言:PHP5.4版本引入了一個非常便利的新功能-可以使用callable類型提示參數來接受可呼叫的函數或方法。這個新功能使得函數和方法可以直接指定對應的可呼叫參數,而無需進行額外的檢查和轉換。在本文中,我們將介紹callable類型提示的使用方法,並提供一些程式碼範例,

產品參數是指產品屬性的意思。例如服裝參數有品牌、材質、型號、大小、風格、布料、適應人群和顏色等;食品參數有品牌、重量、材質、衛生許可證號碼、適應人群和顏色等;家電參數有品牌、尺寸、顏色、產地、適應電壓、訊號、介面和功率等。

C++參數類型安全檢查透過編譯時檢查、執行時間檢查和靜態斷言確保函數只接受預期類型的值,防止意外行為和程式崩潰:編譯時類型檢查:編譯器檢查類型相容性。運行時類型檢查:使用dynamic_cast檢查類型相容性,不符則拋出異常。靜態斷言:在編譯時對型別條件進行斷言。

在開發過程中,我們可能會遇到這樣一個錯誤提示:PHPWarning:in_array()expectsparameter。這個錯誤提示會在使用in_array()函數時出現,有可能是因為函數的參數傳遞不正確所導致的。以下我們來看看這個錯誤提示的解決方法。首先,需要明確in_array()函數的作用:檢查一個值是否在陣列中存在。此函數的原型為:in_a

雙曲函數是使用雙曲線而不是圓定義的,與普通三角函數相當。它從提供的弧度角傳回雙曲正弦函數中的比率參數。但要做相反的事,或者換句話說。如果我們想要根據雙曲正弦值計算角度,我們需要像雙曲反正弦運算一樣的反雙曲三角運算。本課程將示範如何使用C++中的雙曲反正弦(asinh)函數,並使用雙曲正弦值(以弧度為單位)計算角度。雙曲反正弦運算遵循下列公式-$$\mathrm{sinh^{-1}x\:=\:In(x\:+\:\sqrt{x^2\:+\:1})},其中\:In\:是\:自然對數\:(log_e\:k)

i9-12900H是14核心的處理器,使用的架構和工藝都是全新的,線程也很高,整體的工作都是很優秀的,一些參數都有提升特別的全面,是可以給用戶們帶來極佳體驗的。 i9-12900H參數評測大全評測:1、i9-12900H是14核心的處理器,採用了q1架構以及24576kb的製程工藝,提升到了20個執行緒。 2.最大的CPU頻率是1.80!5.00ghz,整體主要取決於工作的負載。 3.相比較價位來說還是特別合適的,性價比很不錯,對於一些需要正常使用的伙伴來說非常的合適。 i9-12900H參數評測大全性能跑分

大型語言模型(LLM)雖然性能強勁,但動輒幾百上千億的參數量,對計算設備還是內存的需求量之大,都不是一般公司能承受得住的。量化(Quantization)是常見的壓縮操作,透過降低模型權重的精度(如32bit降為8bit),犧牲一部分模型的效能來換取更快的推理速度,更少的記憶體需求。但對於超過1000億參數量的LLM來說,現有的壓縮方法都無法維持模型的準確率,也無法在硬體上有效率地運作。最近,麻省理工學院和英偉達的研究人員聯合提出了一個通用後訓練的量化(GPQ, general-purpose po

能打得過GPT-4的開源模型出現了!大模型競技場最新戰報:1040億參數開源模型CommandR+攀升至第6位,與GPT-4-0314打成平手,超過了GPT-4-0613。圖片這也是第一個在大模型競技場上擊敗GPT-4的開放權重模型。大模型競技場,可是大神Karpathy口中唯二信任的測試基準之一。圖片CommandR+來自AI獨角獸Cohere。這家大模型新創公司的共同創辦人兼CEO,正是Transformer最年輕作者AidanGomez(簡稱割麥子)。圖片這份戰報一出,又掀起了一波大模型社
