Monitoring active connections in a database server like MySQL or MariaDB is a crucial task for ensuring efficient operation. By checking user connections, database administrators can assess the server’s current load and spot potential problems. High connection counts could indicate issues such as connection leaks or improper usage, which could affect server performance.
Both MySQL and MariaDB provide commands that allow administrators to list active connections. This helps track users currently interacting with the database and the actions they are performing. Monitoring this information allows administrators to manage server resources more effectively and address performance bottlenecks.
Commands like SHOW PROCESSLIST give a detailed view of active sessions, including the users and the processes running on the server. This real-time data helps administrators stay informed about who is connected and the load they are placing on the database. Knowing how to view these connections is vital for maintaining a healthy database environment.
Steps to view active connections in MySQL or MariaDB:
- Access the MySQL or MariaDB shell with the appropriate user credentials.
$ mysql -u root -p Enter password: ********
- Switch to the database named mysql.
USE mysql;
- Display all active connections using the SHOW PROCESSLIST command.
SHOW PROCESSLIST; +----+------+-----------+------+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+-------+------------------+ | 10 | root | localhost | test | Query | 0 | init | SELECT * FROM tbl| +----+------+-----------+------+---------+------+-------+------------------+
The output will display a list of active connections including their ID, User, Host, DB they're connected to, and the Command they're executing, among other details.
- To display only active users and their hosts, use a filtered query.
SELECT user, host FROM processlist;
This command filters the full process list and shows only the usernames and their associated hosts.
- To count the total number of active connections, run a count query.
SELECT COUNT(*) as "Active Connections" FROM processlist;
- Exit the MySQL or MariaDB shell when done.
EXIT;

Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.