Created
April 17, 2013 14:40
-
-
Save maltzsama/5404843 to your computer and use it in GitHub Desktop.
User list of MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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