查看当前MySQL 链接数 connected
SHOW STATUS LIKE 'Threads%'
Threads_connected显示的数值就是当前的连接数

查看MySQL系统最大链接数 max_connections
show variables like '%max_connections%'

该参数设置过小的最明显特征是出现”Too many connections”错误;
全局每个用户最大连接数 max_user_connections
show variables like 'max_user_connections'

默认情况值为 0。代表:不限制用户资源的。
设置全局每个用户最大连接数
set global max_user_connections=1
响应的连接数 max_used_connections
show variables like 'max_connections' 最大连接数
show status like 'max_used_connections'响应的连接数。
mysql> show variables like ‘max_connections‘;
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| max_connections | 256 |
+-----------------------+-------+
mysql> show status like ‘max_used_connections‘;
+-----------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| max_used_connections | 256|
+----------------------------+-------+
max_used_connections / max_connections * 100%(理想值≈ 85%)
如果max_used_connections跟max_connections相同,那么就是max_connections设置过低或者超过服务器负载上限了,低于10%则设置过大。
本文介绍了如何查看MySQL的当前连接数、最大连接数以及每个用户的最大连接数。通过`SHOW STATUS LIKE 'Threads%'`和`SHOW VARIABLES LIKE '%max_connections%'`等命令可以监控这些指标。当`max_used_connections`接近`max_connections`时,可能表明设置过低或服务器负载过高。理想的利用率约为85%,低于10%则可能设置过大。调整`max_user_connections`可以限制用户连接数,确保系统稳定运行。

5143

被折叠的 条评论
为什么被折叠?



