Skip to content

Instantly share code, notes, and snippets.

@maltzsama
Created April 17, 2013 14:40
Show Gist options
  • Select an option

  • Save maltzsama/5404843 to your computer and use it in GitHub Desktop.

Select an option

Save maltzsama/5404843 to your computer and use it in GitHub Desktop.
User list of MySQL
SHOW PROCESSLIST;
+----+-------------+----------------------+---------------------+---------+-------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+----------------------+---------------------+---------+-------+-------+------------------+
| 12 | root | 192.168.1.1:52451 | NULL | Query | 0 | NULL | SHOW PROCESSLIST |
+----+-------------+----------------------+---------------------+---------+-------+-------+------------------+
8 rows in set (0.01 sec)
SELECT LEFT(host, IF(LOCATE(':', host), LOCATE(':', host), LENGTH(host) + 1) - 1) AS
host_short,GROUP_CONCAT(DISTINCT USER) AS users,COUNT(*)
FROM information_schema.processlist
GROUP BY host_short
ORDER BY COUNT(*),host_short;
--Onde a saída ficará assim:
+----------------+-------------+----------+
| host_short | users | COUNT(*) |
+----------------+-------------+----------+
| 192.168.1.1 | user1 | 1 |
| 192.168.1.1 | user2 | 1 |
| 192.168.1.1 | user3 | 6 |
+----------------+-------------+----------+
3 rows in set (0.01 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment