max_connections 是指整个mysql服务器的最大连接数;
max_user_connections 是指每个数据库用户的最大连接数,比如:虚拟主机可以用这个参数控制每个虚拟主机用户的数据库最大连接数;(历史最大连接数)
例如 GRANT USAGE ON *.* TO 'batchjob1'@'localhost' WITH MAX_USER_CONNECTIONS 10;
mysql> show variables like 'max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 row in set (0.01 sec)
max_connections 值默认为151,
mysql> show status like 'max_used_connections%';
+---------------------------+---------------------+
| Variable_name | Value |
+---------------------------+---------------------+
| Max_used_connections | 5 |
| Max_used_connections_time | 2021-04-19 14:09:43 |
+---------------------------+---------------------+
max_used_connections / max_connections * 100% (理想值≈ 85%)
如果max_used_connections跟max_connections相同 那么就是max_connections设置过低或者超过服务器负载上限了,低于10%则设置过大。
Threads_connected 跟show processlist结果相同,表示当前连接数(当前最大连接数)。准确的来说,Threads_running是代表当前并发数(当前并发数)
mysql> show status like 'Threads%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_cached | 6 |
| Threads_connected | 1 |
| Threads_created | 7 |
| Threads_running | 1 |
+-------------------+-------+
4 rows in set (0.00 sec)