zoukankan      html  css  js  c++  java
  • MySQL--查看数据库连接信息

    =====================================

    查看当前连接到数据库的用户和Host

    ## 查看当前连接到数据库的用户和Host ##
    
    SELECT DISTINCT 
    USER,HOST 
    FROM `information_schema`.`PROCESSLIST` P 
    WHERE P.USER NOT IN('root','repl','system user')   G

     

    =====================================

    查看每个host的当前连接数和总连接数

    SELECT * 
    FROM performance_schema.hosts;

    PS1: 系统表performance_schema.hosts在MySQL 5.6.3版本中引入,用来保存MySQL服务器启动后的连接情况。

     

    =====================================

    按照登录用户+登录服务器查看登录信息

    SELECT 
    USER as login_user,
    LEFT(HOST,POSITION(':' IN HOST)-1) AS login_ip,
    count(1) as login_count
    FROM `information_schema`.`PROCESSLIST` P 
    WHERE P.USER NOT IN('root','repl','system user') 
    GROUP BY USER,LEFT(HOST,POSITION(':' IN HOST)-1)
    ORDER BY COUNT(1) DESC;

    =====================================

    按照登录用户+数据库+登录服务器查看登录信息

    SELECT 
    DB as database_name,
    USER as login_user,
    LEFT(HOST,POSITION(':' IN HOST)-1) AS login_ip,
    count(1) as login_count
    FROM `information_schema`.`PROCESSLIST` P 
    WHERE P.USER NOT IN('root','repl','system user') 
    GROUP BY DB,USER,LEFT(HOST,POSITION(':' IN HOST)-1)
    ORDER BY COUNT(1) DESC;
  • 相关阅读:
    2015 省赛随便写写
    有向图强连通分量
    复杂状态的动态规划
    hdu 3350
    树状DP
    十字链表矩阵
    最优矩阵链乘
    poj 3778
    Poj 3771 hdu 3405
    [2015hdu多校联赛补题]hdu5302 Connect the Graph
  • 原文地址:https://www.cnblogs.com/gaogao67/p/10463168.html
Copyright © 2011-2022 走看看