MySQL: Show Users, Privileges and Passwords

In this article i will show how to list MySQL users, their passwords and granted privileges from the command-line prompt.

MySQL account consists of two components: user and host.

This allows the same user to use different MySQL accounts with different privileges, depending on which host they are connecting from.

In the Host field, besides of the common IP addresses and host names, you can see the % sign, that is a wildcard character that means “any” host.

Important Notice: The % character does not include the localhost, as the localhost means a connection over a UNIX socket instead of a standard TCP/IP.

MySQL: Show Users

Show all MySQL users:

mysql> SELECT user FROM mysql.user;

List only unique user names:

mysql> SELECT DISTINCT user FROM mysql.user;

Show MySQL users and hosts they are allowed to connect from:

mysql> SELECT user,host FROM mysql.user;

Show MySQL users, their passwords and hosts:

mysql> SELECT user,host,password FROM mysql.user;

Cool Tip: Need to change MySQL user password? This can be easily done from the command-line prompt! Read more →

MySQL: Show Privileges

In MySQL, you can use the SHOW GRANTS command to show privileges granted to a user.

Without any additional parameters, the SHOW GRANTS command lists the privileges granted to the current user account with which you have connected to the server.

The SHOW GRANTS requires the SELECT privilege for the mysql database, except to see the privileges for the current user, so if you have such privilege you can also list the privileges granted to the other MySQL users.

Cool Tip: Create a MySQL database and GRANT ALL PRIVILEGES on it to a user! Simple and clear MySQL tutorial with good examples! Read more →

Show privileges granted to the current MySQL user:

mysql> SHOW GRANTS;

Show privileges granted to the MySQL user (if you don’t specify a host for the user name, MySQL assumes % as the host):

mysql> SHOW GRANTS FOR 'USERNAME';

Show privileges granted to a particular MySQL user account from a given host:

mysql> SHOW GRANTS FOR 'USERNAME'@'HOST';

– e.g. –

mysql> SHOW GRANTS FOR 'root'@'localhost';
mysql> SHOW GRANTS FOR 'root'@'%';
mysql> SHOW GRANTS FOR 'admin'@'192.168.0.1';

2 Comment

  1. Or you could just in install percona toolkit and then run pt-show-grants.
    This is a solved problem.

    1. Yeap, u’re right. pt-show-grants shows MySQL users, passwords and grants nicely. But as you have mentioned it requires installation of percona-toolkit while the above commands work out of the box.

Leave a Reply