在使用虛拟主機過程中,如果應用程式連接配接mysql的連接配接數過多,會導緻網頁程式報如下錯誤:
Can not connect to MySQL server
Error: Too many connections
此問題的原因是由于程式沒有及時釋放mysql資料庫連接配接,連接配接數堆積、變滿,導緻新的連接配接無法連接配接到mysql。
1.檢視資料庫的最大連接配接數:
mysql>show variables like '%max_connections%';
+-------------------------+-----------------+
| Variable_name | Value
| extra_max_connections | |
| max_connections | 110 |
共傳回 2 行記錄,花費 121.61 ms.
2.檢視連接配接資料庫IP的連接配接數:
mysql>select SUBSTRING_INDEX(host,':',1) as ip , count(*) from information_schema.processlist group by ip;
+----------------+--------------------+
| ip | count(*) |
| 110.110.10.110 | 1 |
| 110.110.10.111 | 3 |
| 110.110.10.112 | 2 |
| 110.110.10.113 | 1 |
| 110.110.10.114 | 2 |
| 110.110.10.115 | 10 |
| 110.110.10.116 | 2 |
共傳回 7 行記錄,花費 69.87 ms.
3.檢視目前資料庫連接配接狀态:
mysql>show full processlist;
4.kill掉ID持續時間很長的連接配接
mysql>kill 35007306;
本文轉自 guowang327 51CTO部落格,原文連結:http://blog.51cto.com/guowang327/1785805,如需轉載請自行聯系原作者