天天看點

MySql出現“ 1040 Too many connection” 解決方法問題出現情景

MySql出現“ 1040 Too many connection” 解決方法

  • 問題出現情景
    • 解決方法

問題出現情景

多個微服務子產品公用同一個資料庫伺服器導緻大量的sleep線程。而mysql的預設sleep時間是28800秒。。。。預設最大連接配接數為151,這就導緻經常會出現mysql too many connection 的異常

解決方法

mysql> show variables like "max_connections";
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+
1 row in set (0.00 sec)
mysql> set GLOBAL max_connections=1000;
Query OK, 0 rows affected (0.00 sec)
mysql> set global wait_timeout=300;
Query OK, 0 rows affected (0.00 sec)
mysql> 
           

完美解決!!!