方法一:
$ mysql -u username -p
Enter password:
mysql>status;
--------------
mysql Ver 14.14 Distrib 5.7.35, for Linux (x86_64) using EditLine wrapper
Connection id: 12
Current database:
Current user: username@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.35-0ubuntu0.18.04.1 (Ubuntu)
Protocol version: 10
Connection: localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 42 min 6 sec
Threads: 1 Questions: 1186 Slow queries: 0 Opens: 115 Flush tables: 1 Open tables: 60 Queries per second avg: 0.468
--------------
上面的status命令可以查看当前连接数,如果是在客户端机器上,则需要安装MySQL客户端。
方法二:
$ mysqladmin -u username -p status
Enter password:
Uptime: 2717 Threads: 9 Questions: 4406 Slow queries: 0 Opens: 50 Flush tables: 1 Open tables: 44 Queries per second avg: 1.621
这种方法不需要进入MySQL客户端,直接在命令行下执行即可。