Question:Is there a query to run that will return all Users that are currently logged into MySQL?
Answer: In MySQL, there is a system table called information_schema.processlist which shows the threads that are currently running. You can run a query against this system table that returns all of the Users that are currently have a connection running in the MySQL database.
To retrieve all Users logged into MySQL, you can execute the following SQL statement:
This SELECT statement will return the host, the user, and the number of threads for that host/user combination.
The information_schema.processlist table contains the following columns:
Column | Explanation |
---|---|
ID | Unique identifier |
USER | User name (ie: root, AODBA, etc) |
HOST | Host for the user |
DB | Database that thread is running in |
COMMAND | Command that is being run (ie: Query, Sleep, etc). |
TIME | Number of seconds that thread has been running (ie: 3, 12, 353) |
STATE | State of thread (ie: executing) |
INFO | Displays information about the thread. (ie: if COMMAND='Query' and STATE='executing', the SQL that the user is running will be displayed) |