2

Is there some convenient way to see which users are accessing a MySQL database? Ideally I'd have some kind of application making this easy, but other methods would be OK.

If there isn't a standard definition, I would accept "have queried the database in the last 30 minutes".

2 Answers 2

5

How about the query:

SHOW FULL PROCESSLIST 

This will show you connections to the database, what user they are logged in with, the state of the connection, and any currently running command.

1
  • Great. I've created a user with only select_priv and a script that uses that user to run that command so I can parse it to see if it's the only user in the result. This should work! Thanks. Commented Sep 17, 2010 at 22:23
3

From the command line (assuming you have a .my.cnf folder in your home directory),

echo Total\ Connections:; mysqladmin processlist | tail -n +4 | head -n -1 | grep Sleep | wc -l ; echo ; echo Current\ Users: ; mysqladmin processlist | tail -n +4 | head -n -1 | grep Sleep | awk '{print $4}' | sort | uniq 

This gives a nice printout of unique users and total connections.

1
  • 1
    This server is actually Windows 2003, but +1 for a comprehensive one-line solution. (Maybe I'll get to use it on one of my Linux boxen...?) Commented Sep 22, 2010 at 6:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.