MySQL Show Users

A common question most beginner MySQL users ask is how to show all users in MySQL? We have seen this question all over the internet, on our blog and our clients has asked too, how they can list all MySQL users. It’s frequently asked because there are other MySQL commands for displaying information about the database, for example: SHOW DATABASES will list out all the databases, SHOW TABLES will display all the tables in your MySQL database etc. It’s not unusual for people to assume that there should be a “SHOW USERS” command in MySQL. Well, there isn’t one. Luckily there’s a way to show all MySQL users, and in this tutorial we’ll explain how you can list all users in MySQL. 

We’ll assume that you already have MySQL installed on your server. If you haven’t already done so, you can follow one of our LEMP guides and install MySQL.

MySQL List Users – How to List MySQL User Accounts via command line?

Login to MySQL Server as root

First of all, you need to login as root in MySQL using the following command:

## mysql -u root -p

MySQL Show Users

Use the SQL query below to show a list of all MySQL users.

SELECT User, Host, Password FROM mysql.user;

You should get an output of all MySQL users similar to the one below:

| user             | host         | password     |
| root             | localhost    | 37as%#8123fs |
| debian-test-user | localhost    | HmBEqPjC5Y   |
| johnsm           | localhost    |              |
| brian            | localhost    |              |
| root             ||              |
| guest            | %            |              |
| adrianr          |  | RFsgY6aiVg   |
7 rows in set (0.01 sec)

If you want to add more columns or exclude some, just edit the command with the columns you need. You may only need the names of the users, so you can use SELECT User FROM mysql.user;
And that’s all. Using this method you will get a list of all the users in MySQL.

If you want to display only unique usernames that won’t be repeated in more rows, you can use SELECT DISTINCT User FROM mysql.user;, which should give you this output:

| user             | 
| root             | 
| debian-test-user | 
| johnsm           | 
| brian            | 
| guest            | 
| adrianr          | 
6 rows in set (0.01 sec)

How to show current user in MySQL

To get the information on the current user, we use the user() function as shown:

SELECT user();
| user()          |
| local@localhost |
1 row in set (0.00 sec)

Or you use the current_user() function:

SELECT current_user();
| current_user()  |
| local@localhost |
1 row in set (0.00 sec)


In this tutorial, you have learned how to show or list users in MySQL, by querying data from the user table in the MySQL database.

See Also – MySql Create User

mysql show all usersIf you have any additional questions on how to show all users in MySQL, feel free to leave a comment below. You can always get a Managed VPS from us and our fully-managed support will help you with problems related to MySQL, or will explain how to list/show all users in MySql database.

PS. If you liked this post on How to Show All Users in MySQL,  please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.