關於mysql的Too many connections問題
1、問題展現
應用端登入出現Too many connections報錯
檢查發現mysql資料庫服務端已經達到了max_connections上限
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1900 |
+-----------------+-------+
1 row in set (0.00 sec)
mysql> show processlist;
已經達到了1900會話數。
thread_pool設定並不能阻止會話數的上升。
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的服務。重啟完mysql服務後,的確mysql的session數下降了,但是很快會話數又上升到了1900。
判斷並不是mysql的伺服器端的會話沒釋放,而是application端的會話沒釋放。
重啟application的兩臺伺服器,mysql的會話數恢復正常。
3、結論
先來看看mysql伺服器端的會話保持時間:
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:伺服器關閉互動式連線前等待活動的秒數。互動式客戶端定義為在mysql_real_connect()中使用CLIENT_INTERACTIVE選項的客戶端。又見wait_timeout
wait_timeout:伺服器關閉非互動連線之前等待活動的秒數。線上程啟動時,根據全域性wait_timeout值或全域性interactive_timeout值初始化會話wait_timeout值,取決於客戶端型別(由mysql_real_connect()的連線選項CLIENT_INTERACTIVE定義),又見interactive_timeout
如此看來,兩個變數是共同控制的,那麼都必須對他們進行修改了。繼續深入這兩個變數wait_timeout的取值範圍是1-2147483(Windows),1-31536000(linux),interactive_time取值隨wait_timeout變動,它們的預設值都是28800。
MySQL的系統變數由配置檔案控制,當配置檔案中不配置時,系統使用預設值,這個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.
從應用端去降低併發數,減少每個會話的保持時間
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伺服器端增加最大連線數設定,不過會消耗大量記憶體
建議用第二種方法。因為當前應用會話保持時間是10分鐘,建議降低這個數值。
應用端登入出現Too many connections報錯
檢查發現mysql資料庫服務端已經達到了max_connections上限
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1900 |
+-----------------+-------+
1 row in set (0.00 sec)
mysql> show processlist;
已經達到了1900會話數。
thread_pool設定並不能阻止會話數的上升。
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的服務。重啟完mysql服務後,的確mysql的session數下降了,但是很快會話數又上升到了1900。
判斷並不是mysql的伺服器端的會話沒釋放,而是application端的會話沒釋放。
重啟application的兩臺伺服器,mysql的會話數恢復正常。
3、結論
先來看看mysql伺服器端的會話保持時間:
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:伺服器關閉互動式連線前等待活動的秒數。互動式客戶端定義為在mysql_real_connect()中使用CLIENT_INTERACTIVE選項的客戶端。又見wait_timeout
wait_timeout:伺服器關閉非互動連線之前等待活動的秒數。線上程啟動時,根據全域性wait_timeout值或全域性interactive_timeout值初始化會話wait_timeout值,取決於客戶端型別(由mysql_real_connect()的連線選項CLIENT_INTERACTIVE定義),又見interactive_timeout
如此看來,兩個變數是共同控制的,那麼都必須對他們進行修改了。繼續深入這兩個變數wait_timeout的取值範圍是1-2147483(Windows),1-31536000(linux),interactive_time取值隨wait_timeout變動,它們的預設值都是28800。
MySQL的系統變數由配置檔案控制,當配置檔案中不配置時,系統使用預設值,這個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.
從應用端去降低併發數,減少每個會話的保持時間
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伺服器端增加最大連線數設定,不過會消耗大量記憶體
建議用第二種方法。因為當前應用會話保持時間是10分鐘,建議降低這個數值。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29734436/viewspace-2148082/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Mysql中too many connections問題的解決MySql
- MySQL: Too many connectionsMySql
- mysql的max_connections和Too many connectionsMySql
- MySQL問題處理——1040錯誤Too many connectionsMySql
- MySQL ERROR 1040: Too many connectionsMySqlError
- 【MySQL】Too many connections 案例一則MySql
- 解決Mysql錯誤[1040]Too many connectionsMySql
- Ubuntu 解決 Too many open files 問題Ubuntu
- mysql連線數設定操作(Too many connections)及設定md5值的加密密碼MySql加密密碼
- linux Too Many Files 問題檢視和解決方法Linux
- Mysql報Too many connections,不要亂用ulimit了,看看如何正確修改程式的最大檔案數MySqlMIT
- 連線雲虛擬主機中MySQL資料庫時出現“Too many connections”報錯資訊MySql資料庫
- mysql備份提示 too many open files Errornumber 24MySqlError
- 關於mysql連線的問題MySql
- 【Mysql】關於mysql存入emoji表情的問題MySql
- 解決 Too many symbol filesSymbol
- 關於mysql5.6 的排序問題.MySql排序
- Too many open files in system處理
- MySQL關於事務常見的問題MySql
- 關於 mysql 中的 rand () 查詢問題MySql
- Too many open files報錯處理
- [HP-UX] cannot fork: too many processesUX
- NETAPP - LOGIN TOO MANY USERSAPP
- when tag object too many, performance very lowObjectORM
- Too many files with unapproved license異常APP
- 【Mysql】關於一個mysql的坑比時區問題MySql
- 關於 Homestead 連線 MySQL 問題MySql
- 關於mysql中limit最佳化的問題MySqlMIT
- krpano 問題解決之 “Too many active WebGL contexts. Oldest context will be lost.”WebContext
- React報錯之Too many re-rendersReact
- titan-hadoop “Too many open files”修正Hadoop
- 關於 mysql相關的jar影響了tomcat 的問題MySqlJARTomcat
- 關於幾個MySQL環境問題的對比MySql
- 關於mysql和jsp的中文問題~謝謝MySqlJS
- 關於SQLServerDriver的問題SQLServer
- 關於 JavaMail 的問題JavaAI
- 關於session的問題Session
- AIX5.3: Too many processes 0403-030AI