Tablux

Tablux › Guides › MySQL show users

Guide

MySQL show users: how to list users and their privileges

MySQL has no SHOW USERS command. List accounts from the grant table instead: SELECT user, host FROM mysql.user; Then see what one account can do with SHOW GRANTS FOR 'app'@'%'; and which account you are logged in as with SELECT CURRENT_USER();. Reading mysql.user needs the SELECT privilege on it, which root and admin users have.

List all users

Connect as root or another admin account and run:

SELECT user, host FROM mysql.user ORDER BY user, host;
userhost
app%
app_read%
mysql.infoschemalocalhost
mysql.sessionlocalhost
mysql.syslocalhost
reporting10.0.%
rootlocalhost

A MySQL account is a user name and a host. 'app'@'%' (any host) and 'app'@'localhost' would be two separate accounts with their own passwords and privileges, so always look at both columns. % and _ in the host are wildcards: 10.0.% matches any address starting with 10.0.

The mysql.sys, mysql.session and mysql.infoschema accounts are created by MySQL 8.0 for internal use and are locked; leave them alone. MariaDB has mariadb.sys instead, and its default install also creates mysql@localhost. In the mysql command-line client, add \G instead of ; to print wide rows vertically.

Show locked, expired and role accounts

In MySQL 8.0 and later, mysql.user also tells you which accounts are locked, whose password has expired and how they log in:

-- MySQL 8.0 and later
SELECT user, host, account_locked, password_expired, plugin, password_last_changed
FROM mysql.user
ORDER BY user, host;
userhostaccount_lockedpassword_expiredpluginpassword_last_changed
app%NNcaching_sha2_password2026-11-25 23:41:33
app_read%YYcaching_sha2_password2026-11-25 23:41:33
reporting10.0.%YNcaching_sha2_password2026-11-25 23:41:33
rootlocalhostNNcaching_sha2_password2026-11-25 23:34:20

app_read is a role. MySQL stores roles as locked accounts with an expired password and no password set. System accounts are left out of the output above.

In MariaDB (10.4 and later), mysql.user is a view kept for compatibility, and its columns differ: there is an is_role column but no account_locked or password_last_changed. Use SHOW CREATE USER to see whether an account is locked; the full details are in the JSON column priv of mysql.global_priv.

Show a user's privileges with SHOW GRANTS

SHOW GRANTS prints the GRANT statements that would recreate an account's privileges:

SHOW GRANTS FOR 'app'@'%';
Grants for app@%
GRANT USAGE ON *.* TO `app`@`%`
GRANT SELECT, INSERT, UPDATE, DELETE ON `appdb`.* TO `app`@`%`
GRANT `app_read`@`%` TO `app`@`%`
SHOW GRANTS;                                   -- your own account
SHOW GRANTS FOR 'app'@'%' USING 'app_read';    -- MySQL: include the role's privileges
SHOW CREATE USER 'app'@'%';                    -- authentication, TLS, lock, password rules

GRANT USAGE ON *.* means “no global privileges”; every account has that line. If you leave out the host (SHOW GRANTS FOR 'app'), MySQL assumes '%'. MariaDB's output also includes the password hash in an IDENTIFIED BY PASSWORD line, so take care when you paste it into a ticket or chat.

To see the privileges of all users at once, query the information_schema views user_privileges (global), schema_privileges (per database) and table_privileges:

-- Every database-level grant, all users at once
SELECT grantee, table_schema, privilege_type
FROM information_schema.schema_privileges
ORDER BY grantee, table_schema;

Which user am I? USER() vs CURRENT_USER()

SELECT USER(), CURRENT_USER();
-- +---------------+----------------+
-- | USER()        | CURRENT_USER() |
-- +---------------+----------------+
-- | app@localhost | app@%          |
-- +---------------+----------------+

USER() is the name you logged in with and the host you connected from. CURRENT_USER() is the account MySQL matched you to, and it decides your privileges. They differ when a wildcard host matches, as above, or when an anonymous account (''@'localhost') catches a login: if CURRENT_USER() shows an empty user name, you are not the account you think you are. SHOW GRANTS with no FOR shows the privileges of CURRENT_USER().

Create, change and drop users

CREATE USER IF NOT EXISTS 'app'@'%' IDENTIFIED BY 'use-a-long-random-password';
GRANT SELECT, INSERT, UPDATE, DELETE ON appdb.* TO 'app'@'%';

ALTER USER 'app'@'%' IDENTIFIED BY 'a-new-long-password';    -- change the password
RENAME USER 'app'@'%' TO 'app'@'10.0.%';                    -- change name or host
DROP USER IF EXISTS 'app'@'10.0.%';

No FLUSH PRIVILEGES is needed after these statements; it is only for direct edits to the grant tables. DROP USER IF EXISTS gives a note instead of an error when the account is missing. DROP USER does not close the user's open sessions and does not drop objects the user created. Views and stored programs that name the user as DEFINER can fail once it is gone; MySQL 8.4 refuses such a drop unless you hold SET_ANY_DEFINER or ALLOW_NONEXISTENT_DEFINER. For a user that should only read data, follow creating a read-only user in MySQL.

Lock and unlock accounts

Locking keeps the account and its privileges but refuses new logins, which is safer than dropping a user you are not sure about:

ALTER USER 'reporting'@'10.0.%' ACCOUNT LOCK;
ALTER USER 'reporting'@'10.0.%' ACCOUNT UNLOCK;

-- Logging in to a locked account:
-- MySQL:   ERROR 3118 (HY000): Access denied for user 'reporting'@'...'. Account is locked.
-- MariaDB: ERROR 4151 (HY000): Access denied, this account is locked

-- List locked accounts (MySQL)
SELECT user, host FROM mysql.user WHERE account_locked = 'Y';

Sessions that are already connected keep working (tested on MySQL 8.0 and MariaDB 10.11); find them with SHOW PROCESSLIST and end them with KILL. MySQL has supported ACCOUNT LOCK since 5.7.6 and MariaDB since 10.4.

List roles

MySQL 8.0 and MariaDB support roles: named sets of privileges that you grant to users. SHOW GRANTS shows which roles a user has. To see all role assignments:

-- MySQL 8.0: which roles are granted to whom
SELECT from_user AS role, to_user AS user, to_host AS host
FROM mysql.role_edges;

-- MariaDB: roles are rows with is_role = 'Y'; grants are in roles_mapping
SELECT user AS role FROM mysql.user WHERE is_role = 'Y';
SELECT user, host, role FROM mysql.roles_mapping;

SELECT CURRENT_ROLE(); shows the roles active in your session. A granted role is not active at login unless it is a default role, a common reason for “command denied” errors; the read-only user guide shows SET DEFAULT ROLE for both databases.

Privileges needed to list users

Any account can run SHOW GRANTS for itself and SELECT CURRENT_USER(). Listing other accounts needs read access to the mysql system schema:

SELECT user, host FROM mysql.user;
-- ERROR 1142 (42000): SELECT command denied to user 'dev'@'localhost' for table 'user'

-- Let a monitoring or admin account read the account list (and nothing else in mysql):
GRANT SELECT ON mysql.user TO 'monitor'@'10.0.%';

SHOW GRANTS FOR another account likewise needs SELECT on the mysql schema (MariaDB answers ERROR 1044: Access denied … to database 'mysql'). Do not grant SELECT ON *.* to see users: that includes the password hashes in mysql.user.

Managed services: Amazon RDS and PlanetScale

Amazon RDS for MySQL and MariaDB. The master user you chose at setup has global SELECT and CREATE USER, so every query on this page works. You will also see accounts that RDS manages, such as rdsadmin; RDS does not let you drop, rename or change them. There is no SUPER privilege for the master user.

PlanetScale. PlanetScale's MySQL-compatible databases run on Vitess, which does not support MySQL's own user and privilege management, so CREATE USER and GRANT are not the way to manage access there. Database credentials are passwords created in the dashboard, API or CLI, each with a role (reader, writer, readwriter or admin). List them with:

pscale password list <database> <branch>

Running these in a client

These are plain SQL statements, so they work in the mysql command-line client and in GUI clients such as Tablux on Mac, iPhone and iPad, where the result appears as a table. Connect as an account that may read the mysql schema. Tested on MySQL 8.0 and MariaDB 10.11.

Questions

Is there a SHOW USERS command in MySQL?

No. Use SELECT user, host FROM mysql.user; to list accounts, and SHOW GRANTS FOR 'name'@'host'; to see one account's privileges.

How do I see the privileges of a MySQL user?

Run SHOW GRANTS FOR 'user'@'host';. For all users at once, query information_schema.user_privileges, schema_privileges and table_privileges.

Why does SELECT FROM mysql.user say SELECT command denied?

Your account has no SELECT privilege on the mysql system schema. Ask an admin, or connect as root or your managed service's master user.

What is the difference between USER() and CURRENT_USER()?

USER() is the name and host you connected with. CURRENT_USER() is the account MySQL matched, such as app@% for a wildcard host, and it decides your privileges.

How do I list users in MariaDB?

The same query works: SELECT user, host FROM mysql.user;. In MariaDB 10.4+ mysql.user is a view; roles have is_role = 'Y'.

Updated 2026-11-26