CREATE USER 'app_user'@'%' IDENTIFIED BY 'replace-with-strong-password';Host matching matters in MySQL accounts; `%` allows connections from any host.
create users, alter passwords, grant privileges, show grants, revoke access, and manage MySQL accounts safely.
Create and modify accounts for applications, admins, and services.
CREATE USER 'app_user'@'%' IDENTIFIED BY 'replace-with-strong-password';Host matching matters in MySQL accounts; `%` allows connections from any host.
ALTER USER 'app_user'@'%' IDENTIFIED BY 'new-strong-password';Password rotation is a standard operational task for service accounts.
DROP USER IF EXISTS 'old_user'@'%';Use with care because dropping a user removes its login access immediately.
Inspect who MySQL believes you are.
SELECT USER(), CURRENT_USER();These can differ because of authentication and account resolution behavior.
SELECT user, host FROM mysql.user ORDER BY user, host;Requires appropriate privileges to inspect system tables.
Grant and inspect privileges for application and admin workflows.
Allow an app account to use one schema.
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 app_db.* TO 'admin_user'@'%';Convenient in development; more restrictive grants are safer in production.
Inspect the effective privileges granted to an account.
SHOW GRANTS FOR 'app_user'@'%';Always verify grants after provisioning service accounts.
REVOKE DELETE ON app_db.* FROM 'app_user'@'%';Use revoke to tighten access when an account should no longer perform certain operations.
Refresh privilege data after direct system-table changes.
FLUSH PRIVILEGES;Usually unnecessary when using `CREATE USER`, `GRANT`, or `REVOKE`, but sometimes seen in legacy workflows.