【MySQL】MySQL 链接数以及max_used_connections、max_connections和max_user_connections区别

查看当前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%则设置过大。

猜你喜欢

转载自blog.csdn.net/ihero/article/details/127850954