MySQL 网络访问连接

查看 /etc/hosts配置文件

[hotspot@bogon ~]$ cat /etc/hosts
127.0.0.1  localhost localhost.localdomain localhost4 localhost4.localdomain
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.11.52 bogon

分主机查看连接数

mysql> select count(1) '连接数',host_db.host '客户端' from ( select substring_index(host,':',1) as "host" from processlist ) host_db group by host_db.host;
+------+---------------+
| 连接数 | 客户端          |
+------+---------------+
|    3 | 172.16.91.237 |
|    3 | 172.16.91.249 |
|  186 | bogon         |
|   12 | localhost     |
+------+---------------+
4 rows in set

上面表格中bogon和localhost都是访问本机,但连接数的差异,是因为jdbc.url的ip地址使用的不同,如果是127.0.0.1 会被映射为localhost,如果是172.16.11.52 则映射为bogon

分数据库查看连接数

mysql> select count(1) '连接数',db '数据库' from processlist group by db;
+------+--------------------+
| 连接数 | 数据库               |
+------+--------------------+
|    1 | NULL               |
|    3 | bpm                |
|    3 | bpm_ys             |
|    3 | epm                |
|    2 | information_schema |
|  119 | perform2           |
|    5 | pms                |
|   39 | portal             |
|   29 | security_ys        |
+------+--------------------+
9 rows in set

bash 命令行查看连接数

mysql -uroot -proot --database='information_schema' -e "select count(1) '连接数',db '数据库名' from processlist group by db;" 2>/dev/null
原文地址:https://www.cnblogs.com/zhengwenqiang/p/7202789.html