, and
Syntax
CREATE USER 'user'@'host' IDENTIFIED BY 'password'; GRANT privileges ON db.table TO 'user'@'host'; REVOKE privileges ON db.table FROM 'user'@'host';
Parameters
| Parameters | Description | Examples | Level |
|---|---|---|---|
CREATE USER |
New | CREATE USER 'app'@'%' IDENTIFIED BY 'StrongPass123!'; |
Common |
GRANT |
GRANT SELECT, INSERT ON ecommerce.* TO 'app'@'%'; |
Common | |
REVOKE |
REVOKE DELETE ON ecommerce.* FROM 'app'@'%'; |
Common | |
ALTER USER |
() | ALTER USER 'app'@'%' IDENTIFIED BY 'NewPass456!'; |
Common |
DROP USER |
DROP USER IF EXISTS 'temp'@'%'; |
||
SHOW GRANTS |
SHOW GRANTS FOR 'app'@'%'; |
Common |
Examples
--, CREATE USER 'ecommerce_app'@'192.168.1.%' IDENTIFIED BY 'K8s#Prod$2026!'; -- GRANT SELECT, INSERT, UPDATE ON ecommerce.* TO 'ecommerce_app'@'192.168.1.%'; -- New FLUSH PRIVILEGES;
, DELETE and DROP
CREATE USER 'readonly'@'%' IDENTIFIED BY 'ReadOnly2026!'; GRANT SELECT ON ecommerce.* TO 'readonly'@'%'; FLUSH PRIVILEGES;
, and more
-- MySQL 8.0+ Recommended ALTER USER 'ecommerce_app'@'192.168.1.%' IDENTIFIED BY 'NewSecurePass2026!'; -- ALTER USER CURRENT_USER() IDENTIFIED BY 'MyNewPass!';
and
-- SHOW GRANTS FOR 'ecommerce_app'@'192.168.1.%'; -- UPDATE REVOKE UPDATE ON ecommerce.* FROM 'ecommerce_app'@'192.168.1.%'; FLUSH PRIVILEGES;
FLUSH PRIVILEGES
Common Errors
ERROR 1396 (HY000): Operation CREATE USER failed for 'user'@'host'. DROP USER, CREATE USER IF NOT EXISTS(MySQL 8.0+)
ERROR 1044 (42000): Access denied for user (using password: YES)GRANT. root GRANT OPTION
Tips
- root,
- 'user'@'192.168.1.%' IP, 'user'@'%'
- : SELECT user, host FROM mysql.user;