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.
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.
Show Users In MySQL
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 →
Show User Privileges In MySQL
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.
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 'user_name';
Show privileges granted to a particular MySQL user account from a given host:
mysql> SHOW GRANTS FOR 'user_name'@'host';
– e.g. –
mysql> SHOW GRANTS FOR 'root'@'localhost'; mysql> SHOW GRANTS FOR 'root'@'%'; mysql> SHOW GRANTS FOR 'admin'@'192.168.0.1';