`CREATE USER`, `ALTER USER`, `GRANT`, `REVOKE`, and `DROP USER` let DBAs create, modify, secure, and remove MySQL accounts.
Controlling who can read or change data prevents accidental loss, protects customer privacy, and meets compliance rules.
Use CREATE USER
to add accounts and DROP USER
to remove them. Accounts are defined as 'user'@'host'
.
Use GRANT
. Example: GRANT SELECT, INSERT ON ecommerce.Orders TO 'sales_app'@'%';
lets the app read and add orders but not modify products.
ALTER USER
modifies credentials. Always combine with REQUIRE SSL
or IDENTIFIED BY
for stronger security.
Run REVOKE
followed by FLUSH PRIVILEGES
(for older MySQL) to apply changes immediately.
Run SHOW GRANTS FOR 'user'@'host';
to list all active privileges, including database-level and table-level rules.
Grant least privilege, isolate application roles, rotate passwords, enable SSL, and audit accounts periodically.
GRANT ALL
and SUPER
?GRANT ALL
applies only to objects inside the specified scope, while SUPER
is a global admin right. Avoid giving SUPER
to apps.
Run ALTER USER 'temp'@'%' PASSWORD EXPIRE;
. The account must set a new password before the next login.
No. Create separate users per service to avoid cascading failures and simplify auditing.
MySQL defaults to 'user'@'localhost'
. Remote connections will fail until you add a matching host.
Run ALTER USER 'name'@'host' ACCOUNT UNLOCK;
and consider adding stronger password rules.
Yes. Use SHOW GRANTS FOR 'source'@'host'
and paste the result after replacing the target user.