Mysql 查看连接数,状态 最大并发数

1、显示mysql当前状态
mysqladmin -uroot -p status
Uptime: 182341  Threads: 7  Questions: 2831137  Slow queries: 0  Opens: 1536  Flush tables: 3  Open tables: 1171  Queries per second avg: 15.526


Uptime: 182341  MySQL服务器已经运行的秒数
Threads: 7   活跃线程(客户)的数量 
Questions: 2831137 从mysqld启动起来自客户查询的数量
Slow queries: 0    已经超过long_query_time的查询数量 
Opens: 1536    已经打开了多少表 
Flush tables: 3  
Open tables: 1171  现在被打开的表数量
Queries per second avg: 15.526    查询平均用时

2、连接数max_connections
sql> show variables like '%connections%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| max_connections        | 2000  |
| max_user_connections   | 0     |
| mysqlx_max_connections | 100   |
+------------------------+-------+

如果连接数达到最大连接数,那不管剩余多少资源,用户的连接请求都会阻塞在外面。

max_connections,最大连接数,默认100,一般经验设置3000。win服务器连接数支持1500-1800,linux服务器可以支持8000个左右。

另外设置max_user_connections=0,表示不限制用户的最大连接数,其最大值可以等于max_connections

sql> show global status like 'max_used_connections';
检查曾经使用最大的连接数,这个值在max_connections的85%左右比较合适,过高,则会系统使用连接数过少,系统负荷过高。

3、查看 Mysql 连接数、状态、最大并发数
sql> show status like '%max_connections%'; ##mysql最大连接数
sql> set global max_connections=1000 ##重新设置

sql> show variables like '%max_connections%'; ##查询数据库当前设置的最大连接数
sql> show global status like 'Max_used_connections'; ##服务器响应的最大连接数

sql> show status like 'Threads%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_cached    | 34    |
| Threads_connected | 32    |
| Threads_created   | 66    |
| Threads_running   | 2     |
+-------------------+-------+
4 rows in set

参数说明:
Threads_cached  34 ##mysql管理的线程池中还有多少可以被复用的资源
Threads_connected 32 ##打开的连接数
Threads_created 66 ##代表新创建的thread(根据官方文档,如果thread_created增大迅速,需要适当调高 thread_cache_size)。
Threads_running 2 ##激活的连接数,这个数值一般远低于connected数值,准确的来说,Threads_running是代表当前并发数

sql> show variables like 'thread_cache_size'; 
sql> set global thread_cache_size=60;

 

posted on 2017-08-24 16:34  Ruthless  阅读(24380)  评论(0编辑  收藏  举报