MySQL Users, Grants, and Privileges Cheatsheet

create users, alter passwords, grant privileges, show grants, revoke access, and manage MySQL accounts safely.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

user management

Create and modify accounts for applications, admins, and services.

Create a user

Create an account identified by user name and host.

sqlANYcreate-userauth
sql
CREATE USER 'app_user'@'%' IDENTIFIED BY 'replace-with-strong-password';

Host matching matters in MySQL accounts; `%` allows connections from any host.

Change a user's password

Rotate credentials for an existing account.

sqlANYalter-userpassword
sql
ALTER USER 'app_user'@'%' IDENTIFIED BY 'new-strong-password';

Password rotation is a standard operational task for service accounts.

Drop a user

Remove an account from the server.

sqlANYdrop-userauth
sql
DROP USER IF EXISTS 'old_user'@'%';

Use with care because dropping a user removes its login access immediately.

Show the current and authenticated user

Inspect who MySQL believes you are.

sqlANYusercurrent_usersession
sql
SELECT USER(), CURRENT_USER();

These can differ because of authentication and account resolution behavior.

List users from mysql.user

Display existing accounts.

sqlANYmysql.useraccounts
sql
SELECT user, host FROM mysql.user ORDER BY user, host;

Requires appropriate privileges to inspect system tables.

grants and roles

Grant and inspect privileges for application and admin workflows.

Grant privileges on one database

Allow an app account to use one schema.

sqlANYgrantdatabaseprivileges
sql
GRANT SELECT, INSERT, UPDATE, DELETE ON app_db.* TO 'app_user'@'%';

This is a common least-privilege grant for application accounts.

Grant all privileges on a database

Give broad schema-level rights.

sqlANYgrantall-privileges
sql
GRANT ALL PRIVILEGES ON app_db.* TO 'admin_user'@'%';

Convenient in development; more restrictive grants are safer in production.

Show grants for a user

Inspect the effective privileges granted to an account.

sqlANYshow-grantsprivileges
sql
SHOW GRANTS FOR 'app_user'@'%';

Always verify grants after provisioning service accounts.

Revoke privileges

Remove previously granted rights.

sqlANYrevokeprivileges
sql
REVOKE DELETE ON app_db.* FROM 'app_user'@'%';

Use revoke to tighten access when an account should no longer perform certain operations.

Reload grant tables

Refresh privilege data after direct system-table changes.

sqlANYflush-privilegesgrants
sql
FLUSH PRIVILEGES;

Usually unnecessary when using `CREATE USER`, `GRANT`, or `REVOKE`, but sometimes seen in legacy workflows.

Recommended next

No recommendations yet.