1、mysql> show status like '%connect%';
Connections,试图连接到(不管是否成功)MySQL服务器的连接数。
Max_used_connections,服务器启动后已经同时使用的连接的最大数量。
Threads_connected,当前的连接数。
2、mysql> show variables like '%connect%';
max_connections,最大连接数。
3、修改max_connections
在配置文件(my.cnf或my.ini)在最下面,天加一句:
max_connections=32000
然后,用命令重启:/etc/init.d/mysqld restart
虽然这里写的32000,实际MySQL服务器允许的最大连接数16384;
添加了最大允许连接数,对系统消耗增加不大。
4、mysql> show processlist;
显示当前正在执行的MySQL连接。
mysql> show status like '%connect%';
+-----------------------------------------------+---------+
| Variable_name | Value |
+-----------------------------------------------+---------+
| Aborted_connects | 45643 |
| Connection_errors_accept | 0 |
| Connection_errors_internal | 0 |
| Connection_errors_max_connections | 2275689 |
| Connection_errors_peer_address | 15 |
| Connection_errors_select | 0 |
| Connection_errors_tcpwrap | 0 |
| Connections | 145379 |
| Max_used_connections | 152 |
| Performance_schema_session_connect_attrs_lost | 0 |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_finished_connects | 0 |
| Threads_connected | 7 |
+-----------------------------------------------+---------+
14 rows in set (0.00 sec)
mysql> show variables like '%connect%';
+-----------------------------------------------+-----------------+
| Variable_name | Value |
+-----------------------------------------------+-----------------+
| character_set_connection | utf8 |
| collation_connection | utf8_general_ci |
| connect_timeout | 10 |
| disconnect_on_expired_password | ON |
| init_connect | |
| max_connect_errors | 100 |
| max_connections | 151 |
| max_user_connections | 0 |
| performance_schema_session_connect_attrs_size | 512 |
+-----------------------------------------------+-----------------+
9 rows in set (0.00 sec)
mysql> show processlist;
+--------+------+-----------------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+--------+------+-----------------+------+---------+------+-------+------------------+
| 145367 | root | localhost | NULL | Query | 0 | init | show processlist |
| 145373 | root | localhost:58275 | push | Sleep | 179 | | NULL |
| 145374 | root | localhost:58276 | push | Sleep | 179 | | NULL |
| 145375 | root | localhost:58278 | push | Sleep | 179 | | NULL |
| 145376 | root | localhost:58280 | push | Sleep | 0 | | NULL |
| 145377 | root | localhost:58279 | push | Sleep | 2 | | NULL |
| 145378 | root | localhost:58282 | push | Sleep | 0 | | NULL |
+--------+------+-----------------+------+---------+------+-------+------------------+
7 rows in set (0.00 sec)