mysql中Toomanyconnections問題怎么處理-創(chuàng)新互聯(lián)

這篇文章將為大家詳細講解有關(guān)mysql中Too many connections問題怎么處理,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

成都創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),通川企業(yè)網(wǎng)站建設(shè),通川品牌網(wǎng)站建設(shè),網(wǎng)站定制,通川網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,通川網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。

1、問題展現(xiàn)
應(yīng)用端登錄出現(xiàn)Too many connections報錯
mysql中Too many connections問題怎么處理
檢查發(fā)現(xiàn)mysql數(shù)據(jù)庫服務(wù)端已經(jīng)達到了max_connections上限
mysql中Too many connections問題怎么處理
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 1900  |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> show processlist;
已經(jīng)達到了1900會話數(shù)。

thread_pool設(shè)置并不能阻止會話數(shù)的上升。
mysql> show variables like 'thread_pool%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| thread_pool_algorithm                | 0     |
| thread_pool_high_priority_connection | 0     |
| thread_pool_max_unused_threads       | 0     |
| thread_pool_prio_kickup_timer        | 1000  |
| thread_pool_size                     | 16    |
| thread_pool_stall_limit              | 6     |
+--------------------------------------+-------+
6 rows in set (0.00 sec)

2、問題處理
重啟mysql的服務(wù)。重啟完mysql服務(wù)后,的確mysql的session數(shù)下降了,但是很快會話數(shù)又上升到了1900。
判斷并不是mysql的服務(wù)器端的會話沒釋放,而是application端的會話沒釋放。
重啟application的兩臺服務(wù)器,mysql的會話數(shù)恢復(fù)正常。

3、結(jié)論
先來看看mysql服務(wù)器端的會話保持時間:
mysql> show variables like '%wait_timeout%'; 
+--------------------------+----------+ 
| Variable_name | Value | 
+--------------------------+----------+ 
| innodb_lock_wait_timeout | 50 | 
| lock_wait_timeout | 31536000 | 
| wait_timeout | 28800 | 
+--------------------------+----------+ 
3 rows in set (0.00 sec) 

mysql> show variables like '%interactive_timeout%'; 
+---------------------+-------+ 
| Variable_name | Value | 
+---------------------+-------+ 
| interactive_timeout | 28800 | 
+---------------------+-------+ 
1 row in set (0.00 sec) 

interactive_timeout:服務(wù)器關(guān)閉交互式連接前等待活動的秒數(shù)。交互式客戶端定義為在mysql_real_connect()中使用CLIENT_INTERACTIVE選項的客戶端。又見wait_timeout 
wait_timeout:服務(wù)器關(guān)閉非交互連接之前等待活動的秒數(shù)。在線程啟動時,根據(jù)全局wait_timeout值或全局interactive_timeout值初始化會話wait_timeout值,取決于客戶端類型(由mysql_real_connect()的連接選項CLIENT_INTERACTIVE定義),又見interactive_timeout 
如此看來,兩個變量是共同控制的,那么都必須對他們進行修改了。繼續(xù)深入這兩個變量wait_timeout的取值范圍是1-2147483(Windows),1-31536000(linux),interactive_time取值隨wait_timeout變動,它們的默認值都是28800。 
MySQL的系統(tǒng)變量由配置文件控制,當配置文件中不配置時,系統(tǒng)使用默認值,這個28800就是默認值。要修改就只能在配置文件里修改。Windows下在%MySQL HOME%/bin下有mysql.ini配置文件,打開后添加兩個變量,賦值。 

要解決這個問題:
1、Use connection pooling at client side (in MySQL Connector) to reduce the number of active connections between the client and the server. 
是在客戶端安裝MySQL Connector
2、Improve the application design to reduce the number of active connections needed and to reduce the time the connection has to stay active. 
從應(yīng)用端去降低并發(fā)數(shù),減少每個會話的保持時間
3、Increase the number of connections handled by MySQL server by adjusting max_connections (keep in mind that this consumes additional RAM and is still limited)
在mysql服務(wù)器端增加大連接數(shù)設(shè)置,不過會消耗大量內(nèi)存

建議用第二種方法。因為當前應(yīng)用會話保持時間是10分鐘,建議降低這個數(shù)值。

關(guān)于“mysql中Too many connections問題怎么處理”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

標題名稱:mysql中Toomanyconnections問題怎么處理-創(chuàng)新互聯(lián)
URL地址:http://muchs.cn/article22/dcgpcc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計、營銷型網(wǎng)站建設(shè)、做網(wǎng)站、電子商務(wù)、靜態(tài)網(wǎng)站、網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司