Show Users in MySQL

Show Users in MySQL

When managing a database, it is often needed to get a list of users which are used to connect to the MySQL server. MySQL provides statements which allows showing databases and tables, but there is no statement to show users.

Show users list

Users are stored in the mysql.user system table. We can get a list of users by running a SELECT statement.

SELECT * FROM mysql.user;

Show current user

We can get the username and hostname for the MySQL user that the server used to authenticate the current client by the using CURRENT_USER() function.

SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| root@localhost |
+----------------+

Show current logged users list

We can use the information_schema.processlist table to get a list of users that are currently logged in the MySQL server.

SELECT * FROM information_schema.processlist;

Leave a Comment

Cancel reply

Your email address will not be published.