简体   繁体   中英

Why too many connections in MySQL

Recently I've discovered that I have too many connections in my MySQL database:

mysql> show status like 'Conn%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Connections   | 39    |
+---------------+-------+
1 row in set (0.00 sec)

mysql> show full processlist;
+----+-------+-----------+--------+---------+------+-------+-----------------------+
| Id | User  | Host      | db     | Command | Time | State | Info                  |
+----+-------+-----------+--------+---------+------+-------+-----------------------+
| 38 | enrmr | localhost | cakedb | Query   |    0 | NULL  | show full processlist |
+----+-------+-----------+--------+---------+------+-------+-----------------------+

I've recently installed CakePHP and every time I refresh the main page (F5) the number of connections is incremented in one. Also if I restart again mysql the number of connections al still 39.

My netstat output

netstat -n -a | grep 3306
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               ESCUCHAR   

I suppose that I have something like 'mysql zombies connections'. How can I kill them? And how I can stop the creations of new connections every time the web page is refreshed? (Can I only have one connection ?) Thanks.

First, Connections is an incremental counter, it's not current connections. It's total number of connections that were established and/or closed to MySQL instance.

If you want current connections look at Threads_connected , rather than Connections .

Secondly, 39 connections is not much, even if it's a total number of connected threads. It all depends on the application, although just one CakePHP instance will probably utilize just one thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM