mysql根据用户名,ip,连接时间查看连接数,进行数据分析

1.查看数据库所有连接概况

使用show full processlist;

mysql> show full processlist;
+------+-------------+----------------------+------------------+-------------+--------+-----------------------------------------------------------------------+-----------------------+
| Id   | User        | Host                 | db               | Command     | Time   | State                                                                 | Info                  |
+------+-------------+----------------------+------------------+-------------+--------+-----------------------------------------------------------------------+-----------------------+
| 5540 | root        | localhost            | NULL             | Query       |      0 | init                                                                  | show full processlist |
+------+-------------+----------------------+------------------+-------------+--------+-----------------------------------------------------------------------+-----------------------+
1 rows in set (0.00 sec)

2.查看总最大连接数

查看max_connections

mysql> show variables like '%max_connections%'; 
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 1000  |
+-----------------+-------+
1 row in set (0.00 sec)

3.查看单个用户最大连接数

查看max_user_connections

mysql> show variables like '%max_user_connections%';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| max_user_connections | 0     |
+----------------------+-------+
1 row in set (0.00 sec)
 

4.根据用户查看当前连接数

mysql> select USER , count(*) from information_schema.processlist group by USER;
+-------------+----------+
| USER        | count(*) |
+-------------+----------+
| repl        |        2 |
| root        |        1 |
| testcarchat |        1 |

+-------------+----------+
3 rows in set (0.01 sec)

5.根据ip查看当前连接数

mysql> select SUBSTRING_INDEX(host,':',1) as ip , count(*) from information_schema.processlist group by ip;
+----------------+----------+
| ip             | count(*) |
+----------------+----------+
| localhost      |        1 |
+----------------+----------+
1 rows in set (0.00 sec)

6.查看连接时间最长的连接信息

mysql> select host,user,time,state,info from information_schema.processlist order by time desc limit 2;
+---------------------+-----------+--------+------------------------------------------------------------------+------+
| host                | user      | time   | state                                                            | info |
+---------------------+-----------+--------+------------------------------------------------------------------+------+
| 10.176.140.18:57122 | repl      | 527410 | Master has sent all binlog to slave; waiting for binlog to be up | NULL |
| 10.176.140.17:58380 | repl      | 527320 | Master has sent all binlog to slave; waiting for binlog to be up | NULL |
+---------------------+-----------+--------+------------------------------------------------------------------+------+
2 rows in set (0.00 sec)
 

注意,其中time的单位为秒

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值